1015. reversible PRIMES (20) C # implementation

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.