Sphere Online Judge

SPOJ Problem Set (classical)

1112. Number Steps

Problem code: NSTEPS

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



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

Added by:Camilo Andrés Varela León
Date:2006-11-25
Time limit:2s
Source limit:50000B
Languages:All except: CLOJ ERL F# JS PERL 6 TECS
Resource:Asia - Tehran 2000

hide comments
2010-08-29 08:55:55 Chandra sekar
What happened to 'Don't post any source code here.'?
2010-08-29 08:04:39 rajasekar
pls tell how to handel this type of error psl please
this my code almost my logic is correct but the complier tell that it is wrong answer
code is following is any one help me
thanks i advance

#include<stdio.h>


int main()
{
int out[10000],n,x,y,z=0,i;
scanf("%d",&n);

for(i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
if(x==y)
{
if(x%2==1)
z=(x*2)-1;
else
z=x*2;
}
else if((x-2)==y)
{
if(x%2==0)
z=(y*2)+2;
else
z=(y*2)+1;
}
else
z=0;
out[i]=z;
}
for(i=0;i<n;i++)
{ if(out[i]!=0)
printf("%d\n",out[i]);
else
printf("No Number\n");
}
return 0;

}


Last edit: 2010-08-29 13:20:41
2010-08-19 07:57:46 Namandeep Singh Chugh
got 3rd time wrong answer...
logic is correct, answers coming correct
am using "No Number\n" in c to get no number printed , any issue with that??
2010-07-24 16:41:47 yyf
very easy,
two different situations
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.