UVA1180 LA2350 Perfect Numbers【完美数】

The early Greeks have made great contributions to the field of mathematics. Among the great mathematicians of this times were Euclid and Pythagoras. The 23 volume Elements of Euclid is still regarded as on of the cornerstones in the study of mathematics.
    Euclid made an important contributions to a problem posed by Pythagoras - that of finding all the perfect numbers. The number 6 is called a perfect number because 6 = 1 + 2 + 3, the sum of all its proper divisors, (i.e. divisors less than 6). Another example of a perfect number is 28, because 28 = 1 + 2 + 4 + 7 + 14, and 1, 2, 4, 7 and 14 are the divisors of 28 less than 28.
    In Book IX of the ‘Elements’ Euclid found all the even perfect numbers. (It has been proven later much later, in the 20-th century that all perfect numbers are even.) Euclid proved that an even number is perfect if it has the form
2p−1(2p − 1)
where both p and 2p − 1 are prime numbers.
    Two thousand years later, Leonhard Euler proved the converse of Euclid’s theorem. That is every even perfect number must be of Euclid’s type. For example, for 6 and 28, we have
6 = 22−1(22 − 1), and 28 = 23−1(23 − 1)
    Perfect numbers are very rare. By 1975, only 24 perfect numbers have been discovered. The first four perfect numbers are 6, 28, 496, and 8128
which correspond to the following values of p
2, 3, 5, and 7.
    You would be given several integer numbers p, which would not necessarily be prime numbers. You have to determine if 2p−1 (2p − 1) is a perfect number. The largest perfect number in this problem will not exceed 233.
Input
The input contains two lines of integers. The first line contains the number of integers appearing on the second line. The second line contains the values of p that should be tested.
Output
For each integer value to be tested output ‘Yes’ or ‘No’ on a line of its own. The output will be ‘Yes’ if the integer value p generates a perfect number and ‘No’ otherwise.
Sample Input
6
2,3,4,5,6,7
Sample Output
Yes
Yes
No
Yes
No
Yes

Regionals 2001 >> Asia - Dhaka

问题链接UVA1180 LA2350 Perfect Numbers
问题简述:(略)
问题分析
    数学计算题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA1180 LA2350 Perfect Numbers */

#include <bits/stdc++.h>

using namespace std;

int primes[] = {2, 3, 5, 7, 13, 17, 19};
const int N = sizeof(primes) / sizeof(int);

int main()
{
    int t, p;
    char c;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%c", &p, &c);

        bool flag = false;
        for(int i = 0; i < N; i++)
            if(p == primes[i]) {flag = true; break;}

        printf(flag ? "Yes\n" : "No\n");
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/tigerisland45/article/details/89477003