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 (<) and D (1), 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
Subject to the effect:
Initially misunderstood the meaning of problems. . . .
In the D-ary number N is not double prime. Dual prime number is the number itself and the countdown are all prime numbers.
Implementation: determining N is prime. If not, output No, otherwise the number fell to the D-band to come over and into a decimal number, determine whether a prime number. If so, the output Yes, otherwise the output No.
复习判断素数知识点 注意 ‘ = ’ !!!
#include <bits / STDC ++ H.> the using namespace STD; BOOL Prime ( int X) { IF (X == 0 || == X . 1 ) { return to false ; } IF (X == 2 ) { return to true ; } for ( int I = 2 ; I <= sqrt (X); I ++) { // this place forgotten = number! ! ! IF (% I X == 0 ) { return to false ; } } return to true ; } int main () { int A; int D; the while (CIN >> A) { IF (A < 0 ) { BREAK ; } CIN >> D; // first determination itself is not a prime number IF (! Prime (A)) { COUT << " No " << endl; Continue ; } // The decimal turn correspondingly String S = "" ; int X; the while(A) { S + = char (% d + A ' 0 ' ); A = A / d; } // COUT S << << endl; // reverse then it is converted to the binary decimal d int L = s.length (); X = 0 ; for ( int I = 0 ; I <L; I ++ ) { X = X * D + S [I] - ' 0 ' ; } // COUT << X < <endl; IF (Prime (X)) { COUT << "Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }