fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. bool check(string num, int len) {
  7. int sum = 0;
  8.  
  9. for (int i = 0; i < len; i++) {
  10. sum += (int) round(
  11. pow((int) (num[i] - '0'), len)
  12. );
  13. }
  14.  
  15. if (sum == stoi(num)) {
  16. return true;
  17. }
  18.  
  19. return false;
  20. }
  21.  
  22. int main() {
  23. ios::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25.  
  26. for (int i = 153; i < 1000; i++) {
  27. if (check(to_string(i), 3)) {
  28. cout << to_string(i) << "\n";
  29. }
  30. }
  31. for (int i = 1000; i < 10000; i++) {
  32. if (check(to_string(i), 4)) {
  33. cout << to_string(i) << "\n";
  34. }
  35. }
  36. for (int i = 10000; i < 100000; i++) {
  37. if (check(to_string(i), 5)) {
  38. cout << to_string(i) << "\n";
  39. }
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.03s 5308KB
stdin
Standard input is empty
stdout
153
370
371
407
1634
8208
9474
54748
92727
93084