Euler_40.cpp (422B)
1 #include "Euler.h" 2 3 int product(std::string champ, int pos) 4 { 5 if (pos == 1) 6 return 1; 7 8 return (champ[pos - 1] - 48) * product (champ, pos / 10); 9 } 10 11 int Euler::ChampernowneConstant() 12 { 13 std::string champernowne; 14 15 for (int i = 1; i <= 1e6; ++i) 16 { 17 champernowne += std::to_string(i); 18 19 if (champernowne.size() >= 1e6) 20 break; 21 } 22 23 return product(champernowne, 1e6); 24 }