版本比较
题解:AT_agc039_c [AGC039C] Division by Two with Something
正文
增加 14 行删除 14 行
63 行未改动6465666768697071728 行未改动8182838485868788899091929394959697989910010110210310410510610710810911011163 行未改动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 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){if(n%T==0) continue;if((2*n)%T) continue;//找到合法的Tint 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' 生成的原串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...所以要改为如果小于等于就+1f[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;//统计答案}printf("%d\n",ans);return 0;}```63 行未改动6465666768697071728 行未改动8182838485868788899091929394959697989910010110210310410510610710810911011163 行未改动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 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){if(n%T==0) continue;if((2*n)%T) continue;//找到合法的Tint 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' 生成的原串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...所以要改为如果小于等于就+1f[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;//统计答案}printf("%d\n",ans);return 0;}```