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.

Input

First 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$$$)

Output

For each test case, print a integer, represents the answer.

ExampleInput
2
3 1
3 2
Output
-1
1
Note

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$$$

加入题单

上一题 下一题 算法标签: