UVa10490 - Mr. Azad and his Son!!!!!

#include <cstdio>
#include <set>
#include <cmath>

using namespace std;

int a[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};

int main()
{
    int n;
    set<int> s;
    double ans;

    #ifndef ONLINE_JUDGE
        freopen("d:\\OJ\\uva_in.txt", "r", stdin);
        //ifstream cin("d:\\OJ\\uva_in.txt");
    #endif // ONLINE_JUDGE

    for (int i = 0; i < 11; i++) {
        s.insert(a[i]);
    }

    while (scanf("%d", &n) == 1 && n != 0) {
        if (n == 11 || n == 23 || n == 29) {
            printf("Given number is prime. But, NO perfect number is available.\n");
            continue;
        }

        if (s.count(n)) {
            ans = pow(2, n - 1) * (pow(2, n) - 1);
            printf("Perfect: %.lf!\n", ans);
        } else {
            printf("Given number is NOT prime! NO perfect number is available.\n");
        }

    }

    return 0;
}

你可能感兴趣的:(UVa10490 - Mr. Azad and his Son!!!!!)