-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpprime.cpp
More file actions
69 lines (64 loc) · 1.66 KB
/
pprime.cpp
File metadata and controls
69 lines (64 loc) · 1.66 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
/*
ID: dswei191
LANG: C++
TASK: pprime
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
ofstream fout("pprime.out");
ifstream fin("pprime.in");
int a, b;
vector<int> vec;
bool isPrime(int t){
if(t < a || t > b){
return false;
}
if(t % 2 == 0){
return false;
}
int sq = (int)sqrt(t)+ 1;
for(int i = 3; i <= sq; i+=2){
if(t % i == 0){
return false;
}
}
vec.push_back(t);
return true;
}
int main(){
fin >> a >> b;
for(int i1 = 1; i1 < 10; i1++){
int t1 = i1;
int t2 = i1 * 10 + i1;
isPrime(t1);
isPrime(t2);
for(int i2 = 0; i2 < 10; i2++){
int t1 = i1 * 100 + i2 * 10 + i1;
int t2 = i1 * 1000 + i2 * 100 + i2 * 10 + i1;
isPrime(t1);
isPrime(t2);
for(int i3 = 0; i3 < 10; i3++){
int t1 = i1 * 10000 + i2 * 1000 + i3 * 100 + i2 * 10 + i1;
int t2 = i1 * 100000 + i2 * 10000 + i3 * 1000 + i3 * 100 + i2 * 10 + i1;
isPrime(t1);
isPrime(t2);
for(int i4 = 0; i4 < 10; i4++){
int t1 = i1 * 1000000 + i2 * 100000 + i3 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
int t2 = i1 * 10000000 + i2 * 1000000 + i3 * 100000 + i4 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
isPrime(t1);
isPrime(t2);
}
}
}
}
sort(vec.begin(), vec.end());
for(int i = 0; i < vec.size(); i++){
fout<<vec[i]<<endl;
}
return 0;
}