408580: GYM103192 K Easy Sigma
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
K. Easy Sigmatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
$$$\Sigma_{i=1}^{n}(-1)^{\lfloor i\sqrt{k} \rfloor}$$$
Seeing this expression, zyw don't understand it, but greatly shocked. Therefore, he asked you to calculate the value of this expreesion.
InputFirst line gives a integer $$$T$$$ ($$$T \leq 10^5$$$)
The 2nd to T+1th lines, each line gives 2 integers $$$n$$$ and $$$k$$$, meaning as the legend. ($$$n \leq 10^9$$$,$$$k \leq 10^4$$$)
OutputFor each test case, print a integer, represents the answer.
ExampleInput2 3 1 3 2Output
-1 1Note
It's easy to calculate the example
$$$(-1)^{\lfloor 1\sqrt{1} \rfloor}+(-1)^{\lfloor 2\sqrt{1} \rfloor}+(-1)^{\lfloor 3\sqrt{1} \rfloor} = (-1)^1 + (-1)^2 + (-1)^3 = -1$$$
$$$(-1)^{\lfloor 1\sqrt{2} \rfloor}+(-1)^{\lfloor 2\sqrt{2} \rfloor}+(-1)^{\lfloor 3\sqrt{2} \rfloor} = (-1)^1 + (-1)^2 + (-1)^4 = 1$$$