版本比较
题解:AT_agc039_c [AGC039C] Division by Two with Something
正文
增加 14 行删除 14 行
63 行未改动646566676868697071728 行未改动818283848586858687888988899091929192939495969798991001019910010110210310410510610310410510610710810911011163 行未改动using namespace std;const int N=4e5+5,mod=998244353;#define int long longint n,a[N],f[N],ans,tmp[N];int read()//快读 int read()//快读{ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}8 行未改动 cin>>w; if(w=='1') a[i]=1; } int cnt=0; for(int T=2;T<=2*n;T+=2) { for(int T=2;T<=2*n;T+=2) { if(n%T==0) continue; if((2*n)%T) continue;//找到合法的T int num=0,len=T/2;//num为合法的A'的个数 if((2*n)%T) continue;//找到合法的T int num=0,len=T/2;//num为合法的A'的个数 for(int j=1;j<=len;j++) num=(num*2+a[j])%mod,tmp[j]=a[j]; //tmp为 与输入串前len位相同的A' 生成的原串
//tmp为 与输入串前len位相同的A' 生成的原串 for(int j=len+1;j<=n;j++) tmp[j]=tmp[j-len]^1; bool flag=1; for(int j=len+1;j<=n;j++) { if(tmp[j]>a[j]){flag=0;break;} if(tmp[j]<a[j]) break; }//判断大小 num+=flag; //因为要包括00000...所以要改为如果小于等于就+1 }//判断大小 num+=flag; //因为要包括00000...所以要改为如果小于等于就+1
f[T]=(f[T]+num)%mod; for(int j=2;T*j<=2*n;j++) f[T*j]=(f[T*j]-f[T]+mod)%mod;//容斥 ans=(ans+f[T]*T)%mod;//统计答案
for(int j=2;T*j<=2*n;j++) f[T*j]=(f[T*j]-f[T]+mod)%mod;//容斥
ans=(ans+f[T]*T)%mod;//统计答案 } printf("%d\n",ans); return 0;}```