Pythagorean triplet $(a,b,c)$ satisfies: $$a^2 + b^2 = c^2$$ You will be given an integer N. You have to count how many triplets a,b,c exist such that $$1 <= a <= b <= c <= N.$$

Input: First line contains T, the number of test cases. Each test case consists of only one integer in one line.

Output: For each test case, print the required answer.

Constraints: $$1 <= T <= 100 \\ 1 <= N <= 10^6$$

Extra space can reduce time complexity

Complexity: $O (n)$ <syntaxhighlight lang="c" name="triplet">


</syntaxhighlight>




blog comments powered by Disqus




This work is licensed under the CC By-SA 3.0 , without all the cruft that would otherwise be put at the bottom of the page.

Sister Sites: GATE CSE Wiki, GATE CSE, Aptitude Overflow