projecteuler---->problem=30----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.

resu=0
for i in range(2,1000000):
	temp=0
	b = i
	while b>0:
		a = b%10
		b /= 10
		temp += a**5
	if temp==i :
		resu += i
print resu

看错题目 以为范围只是局限于5位数,浪费了20多分钟

projecteuler---->problem=30----Digit fifth powers

时间: 2024-08-22 08:53:27

projecteuler---->problem=30----Digit fifth powers的相关文章

Project Euler:Problem 30 Digit fifth powers

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

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

欧拉计划(python) problem 30

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 inclu

TJU Problem 2857 Digit Sorting

原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted Runs: 1704 Several players play a game. Each player chooses a certain number, writes it down (in decimal notation, without leading zeroes) and sorts t

Problem 005——Digit Generator

1583 - Digit Generator For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M . For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore,

Project Euler:Problem 33 Digit cancelling fractions

The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/98 = 4/8, which is correct, is obtained by cancelling the 9s. We shall consider fractions like, 30/50 = 3/5, to be

Project Euler:Problem 74 Digit factorial chains

The number 145 is well known for the property that the sum of the factorial of its digits is equal to 145: 1! + 4! + 5! = 1 + 24 + 120 = 145 Perhaps less well known is 169, in that it produces the longest chain of numbers that link back to 169; it tu

Project Euler:Problem 34 Digit factorials

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not sums they are not included. #include <iostream> #include <v

九章算法面试题30 最短距离和

九章算法官网-原文网址 http://www.jiuzhang.com/problem/30/ 题目 初阶:在一个n*m的矩阵中,有k个点,求矩阵中距离这k个点的距离和最近的点. 进阶:如果要求这个点与所给的k个点不重合,该怎么办? 注:这里的距离采用曼哈顿距离--|x0-x1| + |y0-y1| 解答 初阶:因为采用曼哈顿距离,所以可以分开考虑x坐标和y坐标.将k个点的x坐标排序,可以知道要求的x坐标一定在这k个点的x坐标上,扫描一遍并统计到各个点的x坐标距离和,找到使得距离和最小的x坐标.