fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int countNumber(int n) {
  6. if(n == 0) return 0;
  7. if(n == 1) return 3;
  8. if(n == 3) return 4;
  9.  
  10. int end = sqrt(n), start = 0, result = 0, totalCount = 0;
  11. while(start <= end) {
  12. result = start*start + end*end;
  13. if(result < n) {
  14. totalCount += ((end - start) << 1);
  15. totalCount++;
  16. ++start;
  17. }
  18. else
  19. --end;
  20. }
  21. return totalCount;
  22. }
  23.  
  24. int main() {
  25. for(int i = 1; i <= 64; ++i) {
  26. cout << "Result of " << i << " is " << countNumber(i) << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Result of 1 is 3
Result of 2 is 3
Result of 3 is 4
Result of 4 is 4
Result of 5 is 6
Result of 6 is 8
Result of 7 is 8
Result of 8 is 8
Result of 9 is 9
Result of 10 is 11
Result of 11 is 13
Result of 12 is 13
Result of 13 is 13
Result of 14 is 15
Result of 15 is 15
Result of 16 is 15
Result of 17 is 17
Result of 18 is 19
Result of 19 is 20
Result of 20 is 20
Result of 21 is 22
Result of 22 is 22
Result of 23 is 22
Result of 24 is 22
Result of 25 is 22
Result of 26 is 26
Result of 27 is 28
Result of 28 is 28
Result of 29 is 28
Result of 30 is 30
Result of 31 is 30
Result of 32 is 30
Result of 33 is 31
Result of 34 is 31
Result of 35 is 33
Result of 36 is 33
Result of 37 is 35
Result of 38 is 37
Result of 39 is 37
Result of 40 is 37
Result of 41 is 39
Result of 42 is 41
Result of 43 is 41
Result of 44 is 41
Result of 45 is 41
Result of 46 is 43
Result of 47 is 43
Result of 48 is 43
Result of 49 is 43
Result of 50 is 45
Result of 51 is 48
Result of 52 is 48
Result of 53 is 50
Result of 54 is 52
Result of 55 is 52
Result of 56 is 52
Result of 57 is 52
Result of 58 is 52
Result of 59 is 54
Result of 60 is 54
Result of 61 is 54
Result of 62 is 56
Result of 63 is 56
Result of 64 is 56