fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. inline long long isqrt(long long n){
  5. long double N = n;
  6. N = sqrtl(N);
  7. long long sq = N - 2;
  8. sq = max(sq, 0LL);
  9. while(sq * sq < n){
  10. sq++;
  11. }
  12. if((sq * sq) == n) return sq;
  13. return sq - 1;
  14. }
  15.  
  16. set<long long> a;
  17. int maxSize = 10000;
  18.  
  19. int main(){
  20. for (int i = 1; i <= 20; i++) {
  21. a.insert(i);
  22. }
  23. while (a.size() <= maxSize) {
  24. set<long long> s = a;
  25. for (auto x : a) {
  26. for (auto y : a) {
  27. s.insert(x * x + y * y);
  28. }
  29. }
  30. for (auto x : a) {
  31. for (auto y : a) {
  32. for (auto z : a) {
  33. int d2 = x * x + y * y - z * z;
  34. int d = isqrt(d2);
  35. if (d2 == d * d && d > 0) {
  36. s.insert(d);
  37. }
  38. }
  39. }
  40. }
  41. a = s;
  42. }
  43. int i = 1;
  44. for (auto x : a) {
  45. if (x != i) {
  46. cout << "The first integer that is not in S is " << x << endl;
  47. break;
  48. }
  49. ++i;
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 1.16s 5324KB
stdin
Standard input is empty
stdout
The first integer that is not in S is 640