You are given integers N and X. For each integer k between 0 and X (inclusive), find the number of operations needed until k returns to its original value. Then, compute the sum of all these answers modulo 998244353. The operation is as follows: if k is odd, subtract 1 and divide by 2; otherwise, divide by 2 and add 2^(N-1). The input is given as N and X, and the output should be the sum of the answers for integers between 0 and X (inclusive), modulo 998244353.

# Buggy version:
mod = 998244353
N = int(input())
X = input()

d = []
for n in range(1,N+1):
    if N%n==0 and (N//n)%2==1:
        d.append(n)

p_d = {}

for n in d:
    p_d[n] = 0
    S = []
    for i in range(N):
        j = i//n
        if X[i%n]=='0':
            if j%2==0:
                S.append('0')
            else:
                S.append('1')
        else:
            if j%2==0:
                S.append('1')
            else:
                S.append('0')

    S = ''.join(S)
    s = X[:n][::-1]
    print(S)
    print(X)
    for i in range(n):
        if s[i]=='1':
            p_d[n] += pow(2,i,mod)
    if S<=X:
        p_d[n] += 1


ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n%m==0:
            p_d[n] -= p_d[m]
    ans += p_d[n]*2*n
ans %= mod
print(ans)


# Fixed version:
mod = 998244353
N = int(input())
X = input()
X_ = []
for i in range(N):
    if X[i]=='0':
        X_.append('1')
    else:
        X_.append('0')
X_ = ''.join(X_)

d = []
for n in range(1,N+1):
    if N%n==0 and (N//n)%2==1:
        d.append(n)

p_d = {}

for n in d:
    p_d[n] = 0
    S = (X[:n]+X_[:n])*(N//n//2)+X[:n]
    p_d[n] += int(X[:n],2)%mod
    if S<=X:
        p_d[n] += 1

ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n%m==0:
            p_d[n] -= p_d[m]
    ans += p_d[n]*2*n
ans %= mod
print(ans)

# Buggy version:
mod = 998244353
N = int(input())
X = input()

d = []
for n in range(1,N+1):
    if N%n==0 and n%2==1:
        d.append(n)

p_d = {}

for n in d:
    p_d[n] = 0
    l = N//n
    s = X[:l]
    s_ = ''
    for i in range(l):
        if s[i]=='0':
            s_ = s_+'1'
        else:
            s_ = s_+'0'
    S = ''
    for i in range(n):
        if i%2==0:
            S = S+s
        else:
            S = S+s_
    s = s[::-1]
    for i in range(l):
        if s[i]=='1':
            p_d[n] += pow(2,i,mod)
    if S<=X:
        p_d[n] += 1

d = d[::-1]
ans = 0
for i in range(len(d)):
    n = d[i]
    ans += p_d[n]*2*N//n
    for j in range(i):
        m = d[j]
        if m%n==0:
            ans -= p_d[m]*2*N//n
ans %= mod
print(ans)

# Fixed version:
mod = 998244353
N = int(input())
X = input()

d = []
for n in range(1,N+1):
    if N%n==0 and (N//n)%2==1:
        d.append(n)

p_d = {}

for n in d:
    p_d[n] = 0
    S = []
    for i in range(N):
        j = i//n
        if X[i%n]=='0':
            if j%2==0:
                S.append('0')
            else:
                S.append('1')
        else:
            if j%2==0:
                S.append('1')
            else:
                S.append('0')

    S = ''.join(S)
    s = X[:n][::-1]
    for i in range(n):
        if s[i]=='1':
            p_d[n] += pow(2,i,mod)
    if S<=X:
        p_d[n] += 1

ans = 0
for i in range(len(d)):
    n = d[i]
    for j in range(i):
        m = d[j]
        if n%m==0:
            p_d[n] -= p_d[m]
    ans += p_d[n]*2*n
ans %= mod
print(ans)

# Buggy version:
import sys
input = sys.stdin.readline

mod=998244353

N=int(input())
X=input()

import math
xr=math.ceil(math.sqrt(N))

LIST=[]
for i in range(1,xr+1):
    if N%i==0:
        LIST.append(i)
        LIST.append(N//i)

REP=[l for l in set(LIST) if (N//l)%2==1 and l!=N]

REP.sort(reverse=True)


ANS=2*N*(int(X,2)+1)%mod

def invstr(X,r):
    return bin(int(X,2)^((1<<r)-1))[2:].zfill(r)
    
for r in REP:
    score=-2*N+2*r

    for j in REP[::-1]:
        if j>r and j%r==0:
            score+=2*N-2*j
            break

    #print(r,score)

    XSTR=X[:r]

    kosuu=int(XSTR,2)

    if (XSTR+invstr(XSTR,r))*(N//(r*2))+XSTR<=X:
        kosuu+=1

    ANS+=kosuu*score

print(ANS%mod)

# Fixed version:
import sys
input = sys.stdin.readline

mod=998244353

N=int(input())
X=input()

import math
xr=math.ceil(math.sqrt(N))

LIST=[]
for i in range(1,xr+1):
    if N%i==0:
        LIST.append(i)
        LIST.append(N//i)

REP=[l for l in set(LIST) if (N//l)%2==1 and l!=N]

REP.sort(reverse=True)


ANS=2*N*(int(X,2)+1)%mod

def invstr(X,r):
    return bin(int(X,2)^((1<<r)-1))[2:].zfill(r)

from collections import defaultdict
score=defaultdict(int)

for r in REP:
    score[r]+=2*r-2*N

    for j in REP:
        if r%j==0 and j<r:
            score[j]-=score[r]
  
for r in REP:
    sc=score[r]

    #print(r,score)

    XSTR=X[:r]

    kosuu=int(XSTR,2)

    if (XSTR+invstr(XSTR,r))*(N//(r*2))+XSTR<=X:
        kosuu+=1

    ANS+=kosuu*sc

print(ANS%mod)

# Buggy version:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


    nn = int(input())
    x = input()

    ans = 0
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                if i % 2 != 0:
                    divisors.append(i)
                if i != n // i and (n//i)%2 != 0:
                    divisors.append(n//i)

        divisors.sort(reverse = True)
        return divisors

    fact_n = make_divisors(nn)

    used = {}

    ans = 0

    for i in fact_n:
        num_len = int(nn/i)
        base = x[:num_len]
        can_divide = int(base, 2)+1
        for key, value in used.items():
            if num_len%key == 0:
                can_divide -= value
        if x < (base + format(2**num_len-1-int(base,2), 'b'))*int((i-1)/2)+base:
            can_divide -= 1
        used[num_len] = can_divide
        ans += can_divide*num_len*2
        ans = ans%998244353


    print(ans%998244353)


# Fixed version:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


    nn = int(input())
    x = input()

    ans = 0
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                if i % 2 != 0:
                    divisors.append(i)
                if i != n // i and (n//i)%2 != 0:
                    divisors.append(n//i)

        divisors.sort(reverse = True)
        return divisors

    fact_n = make_divisors(nn)

    used = {}

    ans = 0

    for i in fact_n:
        num_len = int(nn/i)
        base = x[:num_len]
        can_divide = int(base, 2)+1
        for key, value in used.items():
            if num_len%key == 0:
                can_divide -= value
        if x < (base + format(2**num_len-1-int(base,2), 'b').zfill(num_len))*int((i-1)/2)+base:
            can_divide -= 1
        used[num_len] = can_divide
        ans += can_divide*num_len*2
        ans = ans%998244353


    print(ans%998244353)