R=range I=lambda:map(int,input().split()) T,m=I() P=set() for i in R(2,min(m+1,31623)): if m%i<1:P.add(i) while m%i<1:m//=i M=[m] def G(a,b): while a:a,b=b%a,a return b def r(n): for j in R(len(M)): while M[j]%n<1:M[j]//=n P.add(n) while M: n=M.pop() c=int(n**0.25) if n<10**10:r(n) else: while c: x,d=c,1 y=(x*x+1)%n while d<2 and c:x,y,d,c=(x*x+1)%n,(y**4+2*y*y+2)%n,G(abs(x-y),n),c-1 if d>i&1<1:c[d]=c[d]*c[d|1<>i&1])%2] print((v-(m<2))%Q)