#include<stdio.h>
#include<math.h>
int isprime(int x)
{
int n=sqrt(x)+1;
if(x==1)return 0;
if(x==2)return 1;
for(int i=2;i<n;i++)
{
if(x%i==0)return 0;
}
return 1;
}
int solve(int x,int d)
{
int a[1000],count=0,y=x;
while(y)
{
a[count++]=y%d;
y/=d;
}
int sum=0,t=1;
for(int i=count-1;i>=0;i--)
{
sum+=a[i]*t;
t*=d;
}
if(isprime(sum)&&isprime(x))return 1;
else return 0;
}
main()
{
int x,d;
while(scanf("%d",&x)&&x>0)
{
scanf("%d",&d);
if(solve(x,d))printf("Yes\n");
else printf("No\n");
}
}
pat 1015Reversible Primes (20)
最新推荐文章于 2020-06-10 00:29:05 发布