HDU 1999 不可摸数【类似筛法求真因子和】
不可摸数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15591 Accepted Submission(s): 4077
Problem Description
s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何
数m,s(m)都不等于n,则称n为不可摸数.
数m,s(m)都不等于n,则称n为不可摸数.
Input
包含多组数据,首先输入T,表示有T组数据.每组数据1行给出n(2<=n<=1000)是整数。
Output
如果n是不可摸数,输出yes,否则输出no
Sample Input
3
2
5
8
Sample Output
yes
yes
no
Author
Zhousc@ECJTU
Source
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<set> #include<map> #include<sstream> #include<queue> #include<cmath> #include<list> #include<vector> #include<string> using namespace std; #define long long ll const double PI = acos(-1.0); const double eps = 1e-6; const int inf = 0x3f3f3f3f; const int N = 100005; int n, m, tot; int a[10550]={0}; int r[550], c[550]; int x, y, pr, pc; int ok(int n) { int sum = 0; for(int i=1 ;i<n; i++) { if(n % i == 0) { sum += i; } } return sum; } int main() { int t, f = 0; cin >> t; while(t--) { //f = 0; cin >> n; int i = 2; while(i++ <= 3000) { if(ok(i) == n) { f = 1; break; } } printf("%s\n",f?"no":"yes"); } return 0; }
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<set> #include<map> #include<sstream> #include<queue> #include<cmath> #include<list> #include<vector> #include<string> using namespace std; #define long long ll const double PI = acos(-1.0); const double eps = 1e-6; const int inf = 0x3f3f3f3f; const int N = 500005; int n, m, tot; int a[N]; int mp[N]; int x, y, pr, pc; void init() { for(int i=1; i<=N; i++) { for(int j=i+i; j<=N; j+=i) { a[j] += i; } } for(int j=1; j<=N; j++) { if(a[j] <= 1000) mp[a[j]] = 1; //hash标记 } } int main() { int t; cin >> t; init(); while(t--) { cin >> n; printf("%s\n",mp[n]?"no":"yes"); } return 0; }