CATHETEN - Shared cathetus (easy)
For any integer n, we define F(n) as the number of ways in which n can be the cathetus (leg) of a Pythagorean triangle. For example, there is exactly four Pythagorean triangles with 15 as a length for a cathetus.
(8 15 17), (15 20 25), (15 36 39), (15 112 113)
Thus F(15) = 4.
Input
The first line of input contains an integer T, the number of test cases.
Each of the next T lines contains a single integer n.
Output
For each test case, print F(n) on a single line.
Example
Input: 3 5 10 15 Output: 1 1 4
Constraints
0 < T < 10^5 0 < n < 10^9
For your information, my C code ran in 0.08s, whereas my python3 one ran in 0.90s. (Edit 2017-02-11, after compiler changes)
hide comments
aruhanshani:
2020-07-02 05:41:45
this problem will be harder if n can be the cathetus (leg) or ** n can be the hypotenuse (when i think use Fermat's theorem on sums of two squares and bramagupta it seem hard :)) ) |
|
David:
2020-04-01 04:43:30
Francky - Nice problem!
|
|
Shashank Srivastava:
2015-03-07 23:18:04
@Francky could you tell me where my code fails? I have checked for all cases I could think of.
|
|
Archangel:
2015-03-03 23:07:35
great problem, I learnt from it! THANKS Francky :)
|
|
[Lakshman]:
2015-01-14 04:53:29
Now it is possible to get AC with Python(PYPY).
|
|
Francky:
2014-07-24 12:57:51
@wellwet : if I find some minutes, I'll give you a small c-exemple where your code fails ; but you should be able to do so by your own.
|
|
Puneet Gupta:
2014-07-23 23:16:29
Is the problem having O(1) solution?
|
|
Bhavik:
2014-07-23 15:19:55
@Francky: this might be your easiest problem (atleast for me):)
|
|
Mitch Schwartz:
2014-07-21 17:22:32
@wellwet, beauty is subjective, and that sounds like sour grapes to me. If you think the required solution is too ugly, why not just refrain from submitting to the problem? It's as if you submitted solely because you wanted to complain. Francky is good about giving detailed constraints, which lets you get a pretty good idea of whether your solution is fast enough before submitting. And he also puts a lot of thought into choosing constraints that are reasonable.
|
|
wellwet:
2014-07-21 11:51:03
@Francky: why WA in my submissions? Tested in PARI, results are the same.
|
Added by: | Francky |
Date: | 2013-04-19 |
Time limit: | 1.899s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Old problem |