NSTEPS - Number Steps
Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2, ... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.
![Illustration](../../../content/steinersp:nsteps.gif)
You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...10000.
Input
The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.
Output
For each point in the input, write the number written at that point or write No Number if there is none.
Example
Input: 3 4 2 6 6 3 4 Output: 6 12 No Number
hide comments
|
unseen07:
2018-11-10 17:19:48
why do you guys show off your solution here? Don't spoil it for others please. |
|
adipat:
2018-10-12 16:30:55
All you need to do is check if the number falls on the required line (y=x, y=x-2) which means there is a valid result. Once you do that , find the number(n) in terms of x. It's a straightforward formula if you consider x being even and odd for both cases. Just observe the repetitive pattern and derive the formula. |
|
artistic_15:
2018-09-09 21:23:14
AC in first go! Be careful check all possible combinations of coordinates before submitting. |
|
probeta:
2018-08-28 19:17:38
Extend your intuition for all pairs and then code ! |
|
amoghraj:
2018-07-25 21:08:09
and yea no need to pre calculate and it has nothing to do with matrix..(altho you can try !)
|
|
amoghraj:
2018-07-25 21:06:39
when i first saw it, it seemed duckin terrifying..! i struggled for about 20 minutes!
|
|
nitish235:
2018-06-27 19:22:17
i was getting compilation error then i changed int to long long for n.. i got ac!! |
|
nymeria_96:
2018-06-24 14:46:14
My code is running fine on ideone but gives compilation error while submitting. What should I do? |
|
itachi007:
2018-06-10 17:20:15
AC in one go, it's basic maths |
|
itachi_2016:
2018-06-08 01:30:23
No need to pre-compute. This question just requires basic mathematics! |
Added by: | Camilo Andrés Varela León |
Date: | 2006-11-25 |
Time limit: | 1.159s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Asia - Tehran 2000 |