不可摸数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10585 Accepted Submission(s): 2734
Problem Description
s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何 数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
代码:
/*
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=500050;
int m[MAXN],dp[MAXN];
int main(){
int n,T_T;
scanf("%d",&T_T);
memset(m,0,sizeof(m));
memset(dp,0,sizeof(dp));
for(int i=1;i<=MAXN/2;i++)
for(int j=i+i;j<MAXN;j+=i)
m[j]+=i;
for(int i=1;i<MAXN;i++)
if(m[i]<=1000)dp[m[i]]=1;
while(T_T--){
scanf("%d",&n);
if(dp[n])puts("no");
else puts("yes");
}
return 0;
}
*/
/*
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=10010;
int dp[MAXN],t[MAXN];
void initial(){
memset(dp,0,sizeof(dp));
memset(t,0,sizeof(t));
dp[0]=dp[1]=1;
for(int i=2;i<MAXN;i++){
for(int j=1;j<=i/2;j++){
if(i%j==0)dp[i]+=j;
}
if(dp[i]<=1000)t[dp[i]]=1;
}
}
int main(){
int n,T_T;
initial();
scanf("%d",&T_T);
while(T_T--){
scanf("%d",&n);
if(t[n])puts("no");
else puts("yes");
}
return 0;
}
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1010;
int a[MAXN],prime[MAXN];
int jug[MAXN];
void initial(){
int k=0;
memset(a,0,sizeof(a));
memset(jug,0,sizeof(jug));
for(int i=2;i<MAXN;i++){
if(!a[i]){
for(int j=i+i;j<MAXN;j+=i){
a[j]=1;
}
prime[k++]=i;
jug[i+1]=1;
}
}
for(int i=0;i<k;i++)
for(int j=i+1;j<k;j++){
if(prime[i]+prime[j]+1<=1000)
jug[prime[i]+prime[j]+1]=1;
}
}
int main(){
int n,T_T;
initial();
scanf("%d",&T_T);
while(T_T--){
scanf("%d",&n);
if(jug[n])puts("no");
else puts("yes");
}
return 0;
}