Project Euler Homework
|
00001 #include <iostream> 00002 using namespace std; 00003 00004 unsigned 00005 factorial (unsigned short x) 00006 { 00007 unsigned product = 1; 00008 for (unsigned short k = 2; k <= x; k++) 00009 product *= k; 00010 return product; 00011 } 00012 00013 unsigned 00014 f (unsigned x) 00015 { 00016 unsigned sum_of_factorial = 0; 00017 while (x > 0) 00018 { 00019 sum_of_factorial += factorial (x % 10); 00020 x /= 10; 00021 } 00022 return sum_of_factorial; 00023 } 00024 00025 int 00026 main () 00027 { 00028 unsigned sum = 0; 00029 for (unsigned x = 11; x < 1000000; x++) 00030 00031 if (f (x) == x) 00032 sum += x; 00033 00034 cout << sum << endl; 00035 return 0; 00036 } 00037