-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path10235.cpp
More file actions
executable file
·69 lines (58 loc) · 1.19 KB
/
10235.cpp
File metadata and controls
executable file
·69 lines (58 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Problem: Simply Emirp UVa 10235
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 29-03-05
*/
#include <iostream>
#include <cmath>
using namespace std;
const long length = 1000005;
long seive[length];
void genSeive();
long reverse(long n);
int main(){
genSeive();
long input, rev;
bool prime, emirp;
while (cin >> input){
prime = emirp = false;
if (seive[input] == 0)
prime = true;
rev = reverse(input);
if (seive[rev] == 0)
emirp = true;
cout << input;
if (!prime)
cout << " is not prime." << endl;
else if (prime && (input == rev))
cout << " is prime." << endl;
else if (prime && !emirp)
cout << " is prime." << endl;
else if (prime && emirp)
cout << " is emirp." << endl;
}
return 0;
}
long reverse(long n){
int digit = floor(log10(n))+1;
long m;
long result = 0;
while (n != 0){
m = n % 10;
n = n / 10;
if (digit > 1){
result = result + (m * pow(10, --digit));
}
else
result = result + m;
}
return result;
}
void genSeive(){
long i, j;
seive[0]=seive[1] = 1;
for(i = 2; i < length; ++i){
for (j = i + i; j < length; j += i)
seive[j] = 1;
}
}