-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 35
More file actions
56 lines (51 loc) · 1.12 KB
/
Copy pathproblem 35
File metadata and controls
56 lines (51 loc) · 1.12 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
/*e number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
*/
#include <iostream>
#include<math.h>
#include<string>
#include <algorithm>
#include<vector>
using namespace std;
bool prime(int num){
for(int i = 2; i <= pow(num, .5); i++)
if(num % i == 0){
return false;
}
return true;
}
int swap(vector<int> primes){
int counter = 4;
for(auto n : primes){
int num1 = n;
int shift = 1;
while(n > shift * 10){
shift = shift * 10;
}
do{
int first_digit = num1 % 10;
num1 = num1 / 10;
num1 += first_digit * shift;
if(!prime(num1)){
break;
}
}while(num1 != n);
if(num1 == n){
counter++;
}
}
return counter;
}
int main() {
vector<int> primes;
for(int i = 11; i < 1000000; i+= 2){
if(prime(i)){
primes.push_back(i);
}
}
cout << swap(primes) << endl;
// cout << counter << endl;
//cout << prime(97) << endl;
return 0;
}