[ARC144D] AND OR Equation
Problem Statement
You are given positive integers and . Find the number, modulo , of integer sequences that satisfy all of the following conditions:
- for all non-negative integers ().
- for all non-negative integers and ()
Here, and denote the bitwise AND and OR, respectively.
Constraints
Input
Input is given from Standard Input in the following format:
$N$ $K$
Output
Print the number, modulo , of integer sequences that satisfy the conditions.
Sample Input 1
2 1
Sample Output 1
6
The following six integer sequences satisfy the conditions:
Sample Input 2
2 2
Sample Output 2
19
Sample Input 3
100 123456789123456789
二进制的题,考虑拆位处理。
那么会发现,当我们确定了 时,整个函数就确定了
具体写出来,就是
这个式子可以直接打表推出来
那么此时我们知道了所有 的值,我们能否知道有多少个合法的 ?
注意有 的限制,所以要满足任意的数,
上面这个式子的最大值和最小值一定是所有正数的和(设为 )和所有负数的和(设为s2),那么
共有 种选法
注意到
我们可以往这个方向去列式子。枚举最后的绝对值之和。
此时我们还要给每个数分配正负,发现0我们无法分配。枚举有多少个非0点,然后给答案加上
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5,P=998244353;
int n,f[N],iv[N],inv[N],c[N],ans;
long long k;
int C(int x,int y)
{
return 1LL*f[x]*iv[y]%P*iv[x-y]%P;
}
int main()
{
scanf("%d%lld",&n,&k);
c[f[0]=f[1]=iv[0]=iv[1]=inv[1]=c[0]=1]=(k+1)%P;
for(int i=2;i<N;i++)
{
f[i]=1LL*f[i-1]*i%P;
inv[i]=(P-P/i)*1LL*inv[P%i]%P;
iv[i]=1LL*iv[i-1]*inv[i]%P;
c[i]=c[i-1]*((k-i+2)%P)%P*inv[i]%P;
}
for(int i=0,pw=1;i<=n;i++,(pw<<=1)%=P)
(ans+=1LL*pw*C(n,i)%P*c[i+1]%P)%=P;
// printf("%d %d %d\n",i,pw,c[i+1]);
printf("%d",ans);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2022-04-29 [ZRpj9C] chess
2022-04-29 [ZRpj9A] Part
2022-04-29 [ZRpj10C] Dist
2022-04-29 [ZRpj10B] And
2022-04-29 [ZRpj10A] Scape