language: C++ 4.7.2 (gcc-4.7.2)
date: 860 days 2 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cmath>
#include <iostream>
using namespace std;
 
#define EPS 0.0000001
 
int main() {
  int N;
  cin >> N;
  for (int n = 0; n < N; n++) {
    int X;
    cin >> X;
    int count = 0;
    // add EPS to avoid flooring x.99999 to x
    for (int a = 0; a <= sqrt(X/2) + EPS; a++) {
      int b2 = X - a*a; // b^2
      int b = (int) (sqrt(b2) + EPS);
      if (abs(b - sqrt(b2)) < EPS) // check b is an integer
        count++;
    }
    cout << count << endl;
  }
}
  • upload with new input
  • result: Success     time: 0s    memory: 2728 kB     returned value: 0

    5
    10
    25
    3
    0
    1
    1
    2
    0
    1
    1
    
Sample input