admin 管理员组

文章数量: 1087649

1015

#include<iostream>
#include<cmath>
using namespace std;
int IsPrime(int a)
{if (a == 1)return 0;                       //1既不是质数也不是合数;for (int i = 2; i <= sqrt(a); i++)  {if (a%i == 0)return 0;}return 1;
}
int main()
{int n, d;while (cin>>n && n > 0){cin >> d;if (IsPrime(n) == 1){int a[10];int i=0;while (n){a[i++] = n%d;n = n / d;}int t = 0;n = 0;while (i--){n = n*d + a[t++];}if (IsPrime(n) == 1)cout << "Yes" << endl;elsecout << "No" << endl;}elsecout << "No" << endl;}system("pause");return 0;
}

本文标签: 1015