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 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.

#include <iostream>
using namespace std;

int main()
{
	int res = 0;
	for (int i = 2; i <= 1000000; i++)
	{
		int count = 0;
		int a = i;
		while (a)
		{
			int tmp = a % 10;
			a = a / 10;
			count += pow(tmp, 5);
		}
		if (count == i)
			res += count;
	}
	cout << res << endl;
	system("pause");
	return 0;
}
时间: 2024-08-11 05:42:25

Project Euler:Problem 30 Digit fifth powers的相关文章

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 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 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

Project Euler:Problem 40 Champernowne&#39;s constant

An irrational decimal fraction is created by concatenating the positive integers: 0.123456789101112131415161718192021... It can be seen that the 12th digit of the fractional part is 1. If dn represents the nth digit of the fractional part, find the v

Project Euler:Problem 46 Goldbach&#39;s other conjecture

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. 9 = 7 + 2×12 15 = 7 + 2×22 21 = 3 + 2×32 25 = 7 + 2×32 27 = 19 + 2×22 33 = 31 + 2×12 It turns out that the conjecture was f

Project Euler:Problem 90 Cube digit pairs

Each of the six faces on a cube has a different digit (0 to 9) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of 2-digit numbers. For example, the square number 64

Project Euler:Problem 56 Powerful digit sum

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1. Considering natural numbers of the fo

Project Euler:Problem 63 Powerful digit counts

The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power. How many n-digit positive integers exist which are also an nth power? 这样的数字满足以下条件: 对于数位为x的数S=k^x 有 10^(x-1)<=k^x<=10^x-1 #include &qu

Project Euler:Problem 92 Square digit chains

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 → 32 → 13 → 10 → 1 → 1 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89 Therefore any chain that