1 static void main (string [] ARGs) 2 {3 string [] STR; 4 bool flag; 5 Int n = 0, D = 0; 6 list <int> N = new list <int> (); 7 List <int> d = new list <int> (); 8 9 do10 {11 flag = true; 12 STR = console. readline (). split (New char [] {''}); 13 N = convert. toint32 (STR [0]); 14 15 if (n <0) 16 {17 flag = false; 18} 19 else if (n> 100000) 20 {21 console. writeline ("n> 100000, Please re-enter:"); 22} 23 else if (convert. toint32 (S Tr [1]) <= 1 | convert. toint32 (STR [1])> 10) 24 {25 console. writeline ("the D value is out of the range. Please re-enter:"); 26} 27 else28 {29 n. add (convert. toint32 (STR [0]); 30 d. add (convert. toint32 (STR [1]); 31 32} 33} while (flag = true); 34 35 for (Int J = 0; j <D. count; j ++) 36 {37 If (isprime (N [J]) & isprime (reverse (N [J], d [J]) 38 {39 console. writeline ("yes"); 40} 41 else42 {43 console. writeline ("no"); 44} 45} 46 console. readkey (); 47 48} 49 50 public static int reverse (int A, int d) 51 {52 int sum = 0; 53 do54 {55 sum = sum * D + A % d; 56 A = A/D; 57} while (! = 0); 58 59 return sum; 60} 61 62 public static bool isprime (int I) 63 {64 if (I = 0 | I = 1) 65 return false; 66 for (int p = 2; P <I/2; p ++) 67 if (I % P = 0) 68 return false; 69 70 return true; 71 72}
1015. reversible PRIMES (20) C # implementation