def zhuan(str_num,key):#转十进制
sumkey=0
lenn=len(str_num)
for i in range(lenn):
#print(i)
if str_num[i]>='0' and str_num[i]<='9':
vua=ord(str_num[i])-ord('0')
else:
vua=ord(str_num[i])-ord('a')+10
#print('%d %d %d'%(sumkey,vua,lenn-i))
sumkey+=vua*(key**(lenn-1-i))
return sumkey
def zhde(num,key):#十进制转其他进制
i=''
sn=num
while True:
a=sn%key
b=sn//key
i+=str(a)
sn=b
if b==0:
break
#print(i)
return i
def sam(a):
s=a.split(' ')
if len(s)==1:
return s
sa=[]
sa.append(s[0])
scp=[i for i in range(len(s[0]))]
scp.reverse()
scpoy=''
for i in scp:
scpoy+=s[0][i]
sa.append(scpoy)
sa.append(int(s[1]))
return sa
def sus(a):
if a==2 or a==3:
return 1
if a==1 or a==4:
return 0
for i in range(2,int(pow(a,0.5))):
if a%i==0:
return 0
return 1
in_a=[]
num=0
while True:
b=input()
b=sam(b)
if int(b[0])>=0:
in_a.append(b)
else:
break
#print(in_a)
for i in range(len(in_a)):
a=int(in_a[i][0])
if sus(a) == 1:
a = zhde(a, in_a[i][2])
b=zhuan(a,in_a[i][2])
if sus(b)==1:
print('Yes')
else:
print('No')
else:
print('No')