CSES Problem Set Number Spiral Solution
- Time limit: 1.00 s
- Memory limit: 512 MB
Input
The first input line contains an integer : the number of tests.
After this, there are lines, each containing integers and .
Output
For each test, print the number in row and column .
Constraints
Input:
3
2 3
1 1
4 2
Output:
8
1
15
Code:
term=int(input()) | |
while term !=0: | |
y,x=map(int,input().split()) | |
if x > y: | |
if x%2==1: | |
ans=x*x-y+1 | |
else: | |
x=x-1 | |
ans=x*x+y | |
print(ans) | |
else : | |
if y%2==0: | |
ans=y*y-x+1 | |
else: | |
y=y-1 | |
ans=y*y+x | |
print(ans) | |
term=term-1 | |
No comments