fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. unsigned long long is_ok(unsigned int n)
  9. {
  10. unsigned long long sum = 0;
  11. for(int i = 1; i*i <= n; ++i)
  12. {
  13. if (n%i == 0) {
  14. sum += i*i;
  15. if (i*i != n) sum += (n/i)*(n/i);
  16. }
  17. }
  18. unsigned long long sq = sqrt(sum)+0.5;
  19. if (sq*sq == sum) return sum;
  20. return 0;
  21. }
  22.  
  23.  
  24. int main(int argc, const char * argv[])
  25. {
  26. vector<pair<unsigned int,unsigned long long>> p;
  27. for(unsigned int i = 2; i < 10000; ++i)
  28. {
  29. unsigned long long s = is_ok(i);
  30. if (s) p.emplace_back(i,s);
  31. }
  32.  
  33. for(auto x: p)
  34. cout << setw(10) << x.first << " " << setw(10) << x.second << endl;
  35. }
  36.  
Success #stdin #stdout 0s 4244KB
stdin
Standard input is empty
stdout
        42       2500
       246      84100
       287      84100
       728     722500
      1434    2856100
      1673    2856100
      1880    4884100
      4264   24304900
      6237   45024100
      9799   96079204
      9855  113635600