MATHLOVE - Math is Love

Rashid loves mathematics. He recently started to learn how the various function works in mathematics. On his journey through the math world, he came in touch with a function named Y.

He also came to know that, here Y means the summation of number from 0 to n. For example if n = 5, then 

    Y = 0 + 1 + 2 + 3 + 4 + 5 = 15

Now he is wondering if the knows the value of Y, can he find the value of n for the above equation?

Being so very new to the math world, he could not figure out how to approach this new problem. So he came to you for help. Can you help him?

Input

First line of input will be T (1 <= T <= 100000), denoting the number of test cases.

Next T lines will contain the number Y (1 <= Y <= 3*10^9), value of the above function.

Output

For each test case, if there is exist a value of n for which the above function gives the output Y then print that value of n, otherwise print “NAI” (quotes for clarification).

Note: Data set is huge, use scanf, printf for faster input, output.

Sample

Input
5
11
15
21
1
7626

Output
NAI
5
6
1
123

Added by:Jamil Siam
Date:2017-04-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2017-04-09 22:34:02
what is answer for 0 ,NAI or 0
2017-04-07 08:42:41
anyone got AC in JAVA ? im getting TLE .. im solving this by bottom to top DP then applying binary search. I dont get it , why a problem forcing a programmer to use c/c++ ?
2017-04-06 18:08:18 candide
Too easy for a classical problem. Not really brute force nor binary search, better : use basic math. Good for testing your input/output skills ;)

Last edit: 2017-04-09 14:45:37
2017-04-06 16:50:46 hanstan
Touchdown 0.00s lol. All hail fastio :D
2017-04-05 22:57:41
hurrah...easy one ...accepted in one go..
2017-04-05 13:58:17
easy one......accepted in one go
2017-04-05 07:28:18
Easy one AC in 1 go:-)
2017-04-04 20:03:15 Vipul Srivastava
@akshay_27 You cannot know that, and if your solution is correct the compiler won't show wrong answer as you can see many of us have got accepted.
2017-04-04 19:02:43
But for every input i am getting right answer...i don't know what is error in the code..what should i do now...please help
me to find out error
http://discuss.spoj.com/t/dont-know-the-error-i-am-getting-right-answer-but-compiler-says-wrong-answer/22047




Last edit: 2017-04-05 18:21:24
2017-04-04 16:32:51 Vipul Srivastava
The bounds given are correct. Input <=3*10^9.

Last edit: 2017-04-04 16:34:53
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.