-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 46
More file actions
54 lines (48 loc) · 1.08 KB
/
Copy pathproblem 46
File metadata and controls
54 lines (48 loc) · 1.08 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
/*
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
9 = 7 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
*/
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
bool is_prime(int num){
for (int i = 3; i < int(pow(num, .5)) + 1; i += 2){
if (num % i == 0){
return false;
}
}
return true;
}
int main() {
vector<int> primes = {2};
int number = 3;
while (number < 10000){
bool check = 1;
if (is_prime(number)){
primes.push_back(number);
}
else{
for(int i = 0; i < primes.size(); i++){
int x = (pow(((number - primes[i]) / 2), 0.5));
if (pow(((number - primes[i]) / 2), 0.5) == x ){
check = 0;
break;
}
}
if(check){
cout << number <<endl;
return 0;
}
}
number += 2;
}
return 0;
}