solution.cpp 397 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
#include <cmath>
using namespace std;
int main()
{

    int sum = 0, ans;
    for (int i = 1; i <= 1000; i++)
    {
        ans = 0;
        double m = pow(i, 3); //pow double型
        m = (int)m;
        while (m)
        {
            ans += (int)m % 10;
            m /= 10;
        }
        if (ans == i)
            sum++;
    }
    cout << sum << endl;
    return 0;
}