您的位置:首页 > 其它

project euler problem 30

2013-10-20 14:08 369 查看


Digit fifth powers


Problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 14 + 64 + 34 + 44

8208 = 84 + 24 + 04 + 84

9474 = 94 + 44 + 74 + 44
As 1 = 14 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

Answer:
443839
Completed on Sun, 20 Oct 2013, 07:06
题意:求各位数字的5次方之和与原数是否相同,相同则加起来,最后其和为多少?

暴力解决……

#include <iostream>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main()
{
    int i,j,n,sum,sum1=0;
    for(n=2;n<=10000000;n++)
    {
        j=n;
        sum=0;
        while(j)
        {
            int t=j%10;
            sum+=t*t*t*t*t;
            j/=10;
        }
        if(sum==n) sum1+=sum;
    }
    cout<<sum1<<endl;
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: