1015. Reversible Primes (20)

来源:互联网 发布:济宁广电网络客服电话 编辑:程序博客网 时间:2024/05/22 05:06

caution: 1 is not a prime

1234567891011121314151617181920212223
#include <cstdio>int n,d,m;bool isprime(int k){  if(k==1) return false;  for(int i=2;i*i<=k;i++)    if(k%i==0) return false;  return true;}int main(){  scanf("%d",&n);  while(n>0){    scanf("%d",&d);    if(isprime(n)){      for(m=0;n;n/=d)        m=d*m+n%d;      if(isprime(m)) printf("Yes\n");      else printf("No\n");    }    else printf("No\n");    scanf("%d",&n);  }  return 0;}

0 0