题目的意思是:给出一个数N和一个基数D。首先这个数必须是素数。其次,将这个数(1)转为D进制数(2)将这个D进制数反转(3)将反转后的数再转为十进制数,这个十进制数依然是素数。 这样我们就输出“Yes”。
判断素数:一个数N,如果从2到sqrt(N)都不存在因子,则认为这个数是素数。 注意:0和1不是素数。
将十进制数转为n进制数:(待补充。。。)
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.
Now given any two positive integers N (< 105) and D (1 < D <= 10), you are supposed to tell if N is a reversible prime with radix D.
Input Specification:
The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.
Output Specification:
For each test case, print in one line "Yes" if N is a reversible prime with radix D, or "No" if not.
Sample Input:
73 10
23 2
23 10
-2
Sample Output:
Yes
Yes
No
#include
#include
#include
using namespace std;
bool is_Prime(int a)
{
int i;
if(a==0 || a==1) return false;
//注意是i<=sqrt(),之前弄成i>N){
if( N<0 ) break;
cin>>D;
if( is_Prime(N) && is_Prime( change(N,D) )){
cout<<"Yes"<