-
Notifications
You must be signed in to change notification settings - Fork 0
/
levyConjecture.cpp
62 lines (47 loc) · 935 Bytes
/
levyConjecture.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
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
vector<bool> prime(10000, false);
vector<int> primeInt;
int levyCondn( long long int n );
void calcPrimes();
bool isPrime(int n );
int main()
{
calcPrimes();
long long int t;
cin >> t;
for ( long long int i = 0; i < t; i++ ) {
long long int tmp;
cin >> tmp;
printf("%d\n", levyCondn(tmp) );
}
return 0;
}
int levyCondn( long long int n ) {
int ctr = 0;
for ( int i = 0; i < primeInt.size() && primeInt[i] < n && (n - (2 * primeInt[i])) > 0; i++ ) {
if ( prime[primeInt[i]] && prime[n - (2 * primeInt[i])] ) {
ctr++;
}
}
return ctr;
}
void calcPrimes() {
for ( int i = 2; i < 10000; i++ ) {
if ( isPrime(i) ) {
prime[i] = true;
primeInt.push_back(i);
}
}
prime[2] = true;
}
bool isPrime(int n ) {
for ( int i = 2; i < (n / 2) + 1; i++ ) {
if ( n % i == 0 ) {
return false;
}
}
return true;
}