R=range I=lambda:map(int,input().split()) T,m=I() M=[m] P=set() def gcd(a,b): while a:a,b=b%a,a return b while M: n=M.pop() if n<99: for i in R(2,n+1): if n%i<1: P.add(i) while n%i<1:n//=i else: for t in R(int(n**0.25)*2+9): x,d=int(n**0.5)+1,1 y=(x*x+1)%n while d<2:x,y,d=(x*x+1)%n,(y**4+2*y*y+2)%n,gcd(abs(x-y),n) if d0)*1<>i&1] for j in R(N):w*=[1,W[j]][all(b[j]>>i&1for i in S)] v+=[w,-w][len(S)%2] print((v-(m<2))%Q)