-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 34.cpp
More file actions
31 lines (26 loc) · 838 Bytes
/
Copy pathProblem 34.cpp
File metadata and controls
31 lines (26 loc) · 838 Bytes
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
#include <iostream>
unsigned short fakul(unsigned short num) {
if(num > 1) {
return num * fakul(num - 1);
}
return 1; // 0! is also 1
}
int main() {
std::size_t sum_curios_numbers = 0;
// I took randomly this number(9999999) as upper limit and dont calculated it - it worked
for(std::size_t i = 3; i <= 9999999; i++) {
// We need to store the actual number in an extra variable, because we extract every digit and need to modify the number
std::size_t tmp = i;
std::size_t sum_of_factofial_digits = 0;
// extract all the digits of the number and calculate the faculty from them - and sum that up
while(tmp > 0) {
sum_of_factofial_digits += fakul(tmp % 10);
tmp /= 10;
}
if(sum_of_factofial_digits == i) {
sum_curios_numbers += i;
}
}
std::cout << "Sum: " << sum_curios_numbers << '\n';
return 0;
}