Project Euler Homework
|
00001 #include <iostream> 00002 #include "056_bigN.h" 00003 using namespace std; 00004 00005 class bigNdigitsum:public bigN056 00006 { 00007 public: 00008 bigNdigitsum (unsigned x):bigN056 (x) 00009 { 00010 }; 00011 unsigned digitsum (); 00012 }; 00013 00014 unsigned 00015 bigNdigitsum::digitsum () 00016 { 00017 unsigned sum = 0; 00018 for (int i = 0; i < bigN_gps; i++) 00019 for (verylong x = mantissa[i]; x > 0; x /= 10) 00020 sum += x % 10; 00021 return sum; 00022 } 00023 00024 int 00025 main () 00026 { 00027 unsigned max = 0; 00028 00029 for (int a = 1; a <= 100; a++) 00030 { 00031 bigNdigitsum Number (a); 00032 for (int b = 1; b <= 100; b++) 00033 { 00034 unsigned digitsum = Number.digitsum (); 00035 //cout << a << " ^ " << b << " = (" << digitsum << ") " << Number << endl; 00036 if (digitsum > max) 00037 max = digitsum; 00038 Number *= a; 00039 } 00040 } 00041 00042 cout << max << endl; 00043 return 0; 00044 }