KINJUTSU - POWER LEFT
Naruto is in the middle of the fight and his present power is p. He uses Tajū Kage Bunshin no Jutsu (Multiple Shadow Clone Technique) to create maximum n number of clones and he decided to distribute maximum p/2 power to the possible number of clones. First clone will always receive power equal to 1 and i th clone will receive power as i th term of an AP starting with 1 and having sum less than equal to p/2. Now he sends all even clones for observation and odd ones for fighting. After the battle is over only the observation clones and the highest power clone is alive. What is Naruto's power after he call back all his clones?
Input
The first line contains the number of test cases t (t <= 1000). The next following t lines will contain two integers p and n (1 <= p, n <= 10^9).
Output
Output must contains t lines consisting of the answer as mentioned in above question.
Example
Input: 1 200 10 Output: 155
Explanation:- Naruto is going to give 100 power to 10 clones. So there will be an AP with first term as 1 common difference 2. On adding required terms we get 55, and hence total power is 155.
hide comments
naruto09:
2015-12-18 17:22:29
common difference should always be an integer. ??
|
|
sy_117:
2015-08-26 23:44:41
Nice ques. only take care of diff. cases. |
|
Jaswanth:
2015-08-16 13:52:17
easy one to get 1 point don't forget atmost n clones |
|
xMAn:
2015-08-03 11:01:04
getting SIGFPE error :/
|
|
Aman Agarwal:
2015-06-08 10:46:23
Voila! got 1 point..just needed to take care of some silly cases |
|
sdda:
2015-04-14 10:51:43
for those who are getting SIGFPE runtime error.......guys also include the case when n=0 with n=1.....
|
|
Amit Ajaat:
2014-12-22 11:57:18
Akay sir,u please explain ,can we have any real number including (floats)as the common difference of AP or just integers,also u post some more testcases!!!Not everyone watches naruto
|
|
Mordekaiser:
2014-11-06 09:02:09
How to read the problem? The AP is the ability power? Mordekaiser can always use ability power...
|
|
`Ak:
2014-11-06 06:58:04
@Jacob Plachta I feel the question is well explained as it is mentioned that the possible number of clones that can be formed and at last that we have to find the Naruto's power that specifies that the total amount of power left with Naruto.. What do you find unclear in it??
|
|
UJtriumphsâ„¢:
2014-11-05 21:10:52
Some more test cases :)
|
Added by: | `Ak |
Date: | 2014-10-29 |
Time limit: | 0.100s-1s |
Source limit: | 5000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |