-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 30
More file actions
45 lines (37 loc) · 1.12 KB
/
Copy pathproblem 30
File metadata and controls
45 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*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.
*/
/*
(a + 10b + 100c + 1000d) % a = (a^4 + b^4 + c^4 + d^4) % a
*/
#include <iostream>
#include<string>
#include<math.h>
using namespace std;
int main() {
int total = 0;
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
for(int k = 0; k < 10; k++){
for(int l = 0; l < 10; l++){
for(int n = 0; n < 10; n++){
for(int m = 0; m < 10; m++){
int sum_of_pow = pow(i,5) + pow(j,5) + pow(k,5) + pow(l,5) + pow(n,5) + pow(m,5);
int number = i * 100000 + j * 10000 + k * 1000 + l * 100 + n * 10 + m;
if(sum_of_pow == number){
total += number;
}
}
}
}
}
}
}
cout << total - 1 <<endl;
return 0;
}