#include<stdio.h>
#include<math.h>
int index=0, ans[100010]={0},temp[20]={0};
bool judge(int a){//是素数则返回true
int i, sqr=sqrt(a*1.0);
for(i=2;i<=sqr;i++)
if(a%i==0)return false;
return true;
}
int main(){
int i, j, n, nn, d, quan=1, n_ver=0;
for(i=2;i<=100010;i++){ if(judge(i))ans[i]=1; }
scanf("%d",&n);
while(n>0){
scanf("%d",&d);
i=0; nn=n;n_ver=0; quan=1;
while(nn>0){
temp[i++]=nn%d;
nn=nn/d;
}
i--;
while(i>=0){
n_ver+=temp[i--]*quan;
quan=quan*d;
}
if(ans[n]==1 && ans[n_ver]==1)printf("Yes\n");
else printf("No\n");
scanf("%d",&n);
}//while
return 0;
}
PAT-A1015
最新推荐文章于 2022-03-27 14:15:29 发布