1015. Reversible Primes (20) C#实现

 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             do
10             {
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,请重输:");
22                 }
23                 else if (Convert.ToInt32(str[1]) <= 1 || Convert.ToInt32(str[1]) > 10)
24                 {
25                     Console.WriteLine("D值不在范围内,请重输:");
26                 }
27                 else
28                 {
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                 else
42                 {
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             do
54             {
55                 sum = sum * d + a % d;
56                 a = a / d;
57             } while (a != 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         }
时间: 2024-10-22 17:17:07

1015. Reversible Primes (20) C#实现的相关文章

1015. Reversible Primes (20) ——PAT (Advanced Level) Practise

题目信息: 1015. Reversible Primes (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

1015 Reversible Primes (20 分) 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

1015 Reversible Primes (20)(20 分)

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 (&

1015. Reversible Primes (20)

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 (&

PAT:1015. Reversible Primes (20) AC

#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int D[111]; //存放拆解的数字 int DI=0; //D的数组下标 bool isPrime(int n) { if(n<=1) return 0; int sqr=(int)sqrt(1.0*n); for(int i=2 ; i<sqr+1 ; ++i) if(0==n%i) return

pat1015. Reversible Primes (20)

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

PAT 1015 Reversible Primes[求d进制下的逆][简单]

1015 Reversible Primes (20)(20 分)提问 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

pat 1015 Reversible Primes(20 分)

1015 Reversible Primes(20 分) 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 a

1015. Reversible Primes

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 (&