Problem Author: | Hasan Saleh (MathModel) |
Prepared by: | Hasan Saleh (MathModel) |
Edited by: | Hasan Saleh (MathModel) |
Solution
Observe the pattern will be :
This can be proven via expansion of (10^n-1)^2 (Exercise left).
The index handling is easy from the pattern
(1 \le i < n) then answer is .
(i=n) then answer is .
(n<i<2n) then answer is .
(i=2n) then answer is .
(i>2n) then answer is .
for _ in range(int(input())):
n,i=map(int,input().split())
if(1<=i and i<=n-1):
print(9)
elif(i==n):
print(8)
elif(n+1<=i and i<2*n):
print(0)
elif(i==2*n):
print(1)
else:
print(-1)