Problem 30 Digit fifth powers (暴力枚举)

网友投稿 676 2022-10-21

Problem 30 Digit fifth powers (暴力枚举)

Problem 30  Digit fifth powers (暴力枚举)

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 Sat, 29 Oct 2016, 03:12

题解:如果是一个6位数,各位数字5次方之和最大为 6 * 95 = 354294,是一个6位数,所以6位数是有可能满足的。 如果是一个7位数,各位数字5次方之和最大为 7 * 95 = 413343,是一个6位数,不可能等于7位数自身,所以7位数是不可能满足的。注意:As 1 = 14 is not a sum it is not included..

代码

#includeint sum(int n){ int sum=0; int digit = 0; while(n!=0) { digit = n%10; sum += (int)pow((float)digit,5); n /= 10; } return sum;}int main(){ int i; int ans = 0; for (i=10;i<999999;i++) { if (sum(i) == i) { ans += i; } } std::cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:CredSniper是一个使用Python微框架Flask和Jinja2模板编写的网络钓鱼框架
下一篇:Problem 49 Prime permutations (set + vector)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~