project-euler

https://projecteuler.net/
Log | Files | Refs | README

Euler_30.cpp (429B)


      1 #include "Euler.h"
      2 
      3 long Euler::DigitFifthPowers()
      4 {
      5     long sum = 0;
      6 
      7     for (int j = 0 ; j < 500000; ++j)
      8     {
      9         long currentPowerTotal = 0;
     10 
     11         std::string current = std::to_string(j);
     12 
     13         for (unsigned i = 0; i < current.length(); i++)
     14             currentPowerTotal += (int)pow(current.at(i) - 48, 5);
     15 
     16         if (j == currentPowerTotal)
     17             sum += currentPowerTotal;
     18     }
     19 
     20     return sum - 1;
     21 }