PYTRIP2 - Pythagorean triples (medium)
Pythagoras is credited, by tradition, for the first proof of the relation a2 + b2 = c2 in any right angled triangle where c is hypotenuse and a and b are the catheti.
We define a Pythagorean triple as a set of three positive integers a, b, and c which satisfy the above equation, i.e., a2 + b2 = c2.
{3, 4, 5} is the most common example of such a triple.
Input
The first line of input contains an integer T, the number of test cases.
Each of the next T lines contains two integers N, M.
Output
For each test case, print on a single line the number of Pythagorean triplet {a, b, c} such that N ≤ a, b, c ≤ M.
Example
Input: 3 1 5 4 10 10 100 Output: 1 1 45
Constraints
0 < T < 100
0 < N < M
0 < T × M < 1.21×108
There are several input files.
Time limit is ×20 my top speed with C language (1kB of code).
For your information, my total best time is 0.59s for the 6 input files. (Edit 2017-02-11, after compiler changes).
Warning, it could be hard with interpreted languages. You can try the quite similar tutorial problem PYTRIP before.Information
This problem is part of the Bubble Cup competition qualification round (April 2014).
@students: good luck. GNU_salutations.
hide comments
|
Francky:
2014-04-02 23:04:57
some submissions disqualified ; Filip, Vladimir Milenkovic, Irfan Smajevic, muhamed_ikovic@hotmail.com : please try with your own code. Last edit: 2014-04-02 15:17:36 |
|
Dzejlan:
2014-04-02 23:04:57
can you look at my code id=11373860
|
|
Lovro Puzar:
2014-04-02 23:04:57
I believe the constraint T * M < 10^8 is wrong. A passing solution with the addition of assert(T * M < 100000000) trips the assert. Perhaps the author meant sum(M) < 10^8.
|
|
Prodigy:
2014-04-02 23:04:57
for ??? ..output ???
|
Added by: | Francky |
Date: | 2013-04-11 |
Time limit: | 1s-3.400s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |