Language: C++

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=5e5+5;
char s[N];int a[N],b[N],c[N],st[N],n,res,tot,t;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%s",&n,s+1);
	fp(i,1,n)a[i]=s[i]-'0';
	n<<=1;
	fp(k,1,n)if(n%k==0&&((n/k)&1)){
		++tot,b[tot]=k,c[tot]=0;
		R int d=__gcd(n>>1,k);
		fp(i,1,d)c[tot]=((c[tot]<<1)+0ll+a[i])%P;
//		fp(i,1,d)st[i]=a[i];
//		fp(i,d+1,n>>1)st[i]=st[i-d]^1;
		++c[tot];
		fp(i,d+1,n>>1){
			R int x=a[i-d]^1;
			if(x!=a[i]){
				if(x>a[i])--cnt[tot];
				break;
			}
		}
//		fp(i,d+1,n>>1)if(a[i]!=st[i]){
//			c[tot]-=(a[i]<st[i]);
//			break;
//		}
	}
	fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)c[i]-=c[j];
	fp(i,1,tot)upd(res,mul(c[i],b[i]));
	printf("%d\n",res);
	return 0;
}

Compiler output:
a.cc:11:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 | inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
      |                        ^
a.cc:11:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 | inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
      |                                ^
a.cc:12:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
      |                      ^
a.cc:12:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
      |                              ^
a.cc:13:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 | inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
      |                      ^
a.cc:13:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   13 | inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
      |                              ^
a.cc:14:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 | inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
      |                      ^
a.cc:14:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 | inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
      |                              ^
a.cc:15:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   15 | int ksm(R int x,R int y){
      |               ^
a.cc:15:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   15 | int ksm(R int x,R int y){
      |                       ^
a.cc: In function 'int ksm(int, int)':
a.cc:16:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         R int res=1;
      |               ^~~
a.cc: In function 'int main()':
a.cc:25:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |         fp(i,1,n)a[i]=s[i]-'0';
      |            ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:25:9: note: in expansion of macro 'fp'
   25 |         fp(i,1,n)a[i]=s[i]-'0';
      |         ^~
a.cc:27:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |         fp(k,1,n)if(n%k==0&&((n/k)&1)){
      |            ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:27:9: note: in expansion of macro 'fp'
   27 |         fp(k,1,n)if(n%k==0&&((n/k)&1)){
      |         ^~
a.cc:29:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   29 |                 R int d=__gcd(n>>1,k);
      |                       ^
a.cc:30:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   30 |                 fp(i,1,d)c[tot]=((c[tot]<<1)+0ll+a[i])%P;
      |                    ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:30:17: note: in expansion of macro 'fp'
   30 |                 fp(i,1,d)c[tot]=((c[tot]<<1)+0ll+a[i])%P;
      |                 ^~
a.cc:34:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |                 fp(i,d+1,n>>1){
      |                    ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:34:17: note: in expansion of macro 'fp'
   34 |                 fp(i,d+1,n>>1){
      |                 ^~
a.cc:35:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |                         R int x=a[i-d]^1;
      |                               ^
a.cc:37:45: error: 'cnt' was not declared in this scope; did you mean 'int'?
   37 |                                 if(x>a[i])--cnt[tot];
      |                                             ^~~
      |                                             int
a.cc:46:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)c[i]-=c[j];
      |            ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:46:9: note: in expansion of macro 'fp'
   46 |         fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)c[i]-=c[j];
      |         ^~
a.cc:46:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)c[i]-=c[j];
      |                       ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:46:20: note: in expansion of macro 'fp'
   46 |         fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)c[i]-=c[j];
      |                    ^~
a.cc:47:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         fp(i,1,tot)upd(res,mul(c[i],b[i]));
      |            ^
a.cc:4:29: note: in definition of macro 'fp'
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                             ^
a.cc:4:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
      |                                   ^
a.cc:47:9: note: in expansion of macro 'fp'
   47 |         fp(i,1,tot)upd(res,mul(c[i],b[i]));
      |         ^~