-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNonAbundantSums.cpp
72 lines (72 loc) · 1.51 KB
/
NonAbundantSums.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
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000
int SPF[MAX];
void sieve()
{
for(int i = 1;i < MAX;i++)
SPF[i] = i;
for(int i = 4; i < MAX;i = i + 2)
SPF[i] = 2;
for(int i = 3; i * i < MAX;i = i + 1)
{
if(SPF[i] == i)
{
for(int j = i * i; j < MAX;j = j + i)
{
if(SPF[j] == j)
SPF[j] = i;
}
}
}
}
unsigned long long int factorSum(int x)
{
unordered_map<int,int> umap;
int n = x;
while(x != 1)
{
umap[SPF[x]]++;
x = x / SPF[x];
}
unordered_map<int,int> :: iterator it;
unsigned long long int ans = 1;
for(it = umap.begin(); it != umap.end(); it++)
{
ans = ans * (pow(it->first,it->second + 1) - 1) / (it->first - 1);
}
return (ans - n);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
sieve();
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int flag = 0;
for(int i = 1;i <= n/2; i = i+1)
{
if( (factorSum(i) > i) )
{
if(factorSum(n-i) > (n-i))
{
flag = 1;
break;
}
else
{
flag = 0;
continue;
}
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}