-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10235 - Simply Emirp.cpp
116 lines (94 loc) · 2.03 KB
/
10235 - Simply Emirp.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/// Name: Md. Samshad Rahman
/// Prob: 10235 - Simply Emirp
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <string>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <bitset>
#include <utility>
#include <fstream>
#include <set>
#include <ctime>
#define co cout
#define ci cin
#define sf1(x) scanf("%d", &x)
#define tkc(x) scanf("%c", &x)
#define sf scanf
#define pf1(x) printf("%d ", x)
#define pfc(x) printf("%c", x)
#define pf printf
#define FOR(i,j,k) for(i = j; i < k; i++)
#define mem(x,n) memset((x),(n),sizeof((x)))
#define pi acos(-1.0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector< PII > VII;
const double EPS = 1e-11;
#define sz 1000100
int prime[sz];
void sieve(int n)
{
int i, j, sqrtn;
for(i = 2; i <= n; i++)
prime[i] = 0;
sqrtn = ( sqrt( double (n) ));
for(i = 3; i <= sqrtn; i += 2)
{
if(prime[i] == 0)
{
for(j = i * i; j <= n; j += i + i)
prime[j] = 1;
}
}
}
int reversen(int n)
{
int newn = 0;
while(n)
{
newn *= 10;
newn += (n % 10);
n /= 10;
}
return newn;
}
int main()
{
sieve(sz);
prime[1] = 1;
int a, t;
while(scanf("%d", &a) != EOF)
{
if( a % 2 == 0 )
{
if( a == 2 )
printf("%d is prime.\n", a);
else
printf("%d is not prime.\n", a);
}
else if(prime[a] == 0)
{
t = reversen(a);
if( prime[t] == 0 && t != a && (t % 2) != 0 )
printf("%d is emirp.\n", a);
else
printf("%d is prime.\n", a);
}
else
printf("%d is not prime.\n", a);
}
return 0;
}