zcmu.oj-1135:不可摸数

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


分析:
题中的意思是如果所有的2-1000的真因子和S(m)都无法找到一个与n相同的数n
才是不可摸数。例如当n=8时,S(10)=1+2+5=8满足题意故输出NO。求出1000以
内的所有数对应真因子和,然后一一匹配。

代码:
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    int a[5000]={0};
    int i,j,n,m,temp;
    a[1] = 1;
    for(i=2; i<5000; i++)
    {
        a[i] = 0;
        for(j=1; j<i; j++)
        {
            if(i%j==0)
                a[i] += j;
        }
    }
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        temp = 0;
        for(i=2; i<5000; i++)
        {
            if(a[i]==m)
            {
                temp = 1;
                break;
            }
        }
        if(temp==0)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}




猜你喜欢

转载自blog.csdn.net/kyrieee/article/details/80242419