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
版权声明:本文标题:1015 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1700300844a386802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论