fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <numeric>
  4. #include <vector>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. int64_t splitAdd(int64_t value) {
  10. ostringstream intStream;
  11. intStream << value;
  12. string intString(intStream.str());
  13. return accumulate(intString.begin(), intString.end(), 0) - (intString.size() * int64_t('0'));
  14. }
  15.  
  16. int main(int argc, char *argv[]) {
  17. int64_t maxPower = 50;
  18. std::vector<int64_t> results(maxPower);
  19. for (int64_t tuple = 0; tuple <= maxPower; tuple++) {
  20. for (int64_t power = 0; power <= maxPower; power++) {
  21. int64_t value = pow(tuple, power);
  22. while (value > 9) {
  23. value = splitAdd(value);
  24. }
  25. results.at(power) = value;
  26. }
  27. cout << tuple << endl;
  28. for (int i = 0; i < maxPower; i++) {
  29. cout << results.at(i) << ',';
  30. }
  31. cout << endl;
  32. }
  33. }
Runtime error #stdin #stdout #stderr 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 50) >= this->size() (which is 50)