hdu 1999 不可摸数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8274 Accepted Submission(s): 2122
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>
#define N 1000000
int a[N];
//打表求质因子之和
int table()
{
int i,j;
for(i=1; i<=N/2; i++)
for(j=i*2; j<=N; j+=i)
a[j]+=i;
}
int main()
{
table();
/*int i;
for(i=994000; i<=994030; i++){
printf("%d\n",a[i]); //994009对应的是998,无语
}
while(1);*/
int T,n,i,ok;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=1,ok=1; i<N; i++)
{
if(a[i]==n){
printf("no\n");
ok=0;
break;
}
}
if(ok)
printf("yes\n");
}
return 0;
}
/*优化后的代码:
二次打表,省时;
*/
#include<cstdio>
#include<cstring>
#define N 1000000
int a[N];
int table()
{
int i,j;
for(i=1; i<=N/2; i++)
for(j=i*2; j<=N; j+=i)
a[j]+=i;
}
int main()
{
table();
int T,n,i,ok,b[1000];
memset(b,0,sizeof(b));
for(i=1; i<=N; i++)
if(a[i]<=1000) b[a[i]]=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf(b[n]?"no\n":"yes\n");
}
return 0;
}
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8274 Accepted Submission(s): 2122
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>
#define N 1000000
int a[N];
//打表求质因子之和
int table()
{
int i,j;
for(i=1; i<=N/2; i++)
for(j=i*2; j<=N; j+=i)
a[j]+=i;
}
int main()
{
table();
/*int i;
for(i=994000; i<=994030; i++){
printf("%d\n",a[i]); //994009对应的是998,无语
}
while(1);*/
int T,n,i,ok;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=1,ok=1; i<N; i++)
{
if(a[i]==n){
printf("no\n");
ok=0;
break;
}
}
if(ok)
printf("yes\n");
}
return 0;
}
/*优化后的代码:
二次打表,省时;
*/
#include<cstdio>
#include<cstring>
#define N 1000000
int a[N];
int table()
{
int i,j;
for(i=1; i<=N/2; i++)
for(j=i*2; j<=N; j+=i)
a[j]+=i;
}
int main()
{
table();
int T,n,i,ok,b[1000];
memset(b,0,sizeof(b));
for(i=1; i<=N; i++)
if(a[i]<=1000) b[a[i]]=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf(b[n]?"no\n":"yes\n");
}
return 0;
}