#P5172. [清华集训 2014] Sum

    ID: 5891 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2014CTT(清华集训/北大集训)

[清华集训 2014] Sum

Problem Description

Given positive integers nn and rr, compute:

d=1n(1)dr\sum_{d=1}^{n}(-1)^{\lfloor d\sqrt{r} \rfloor}

Input Format

The first line contains an integer tt, indicating that there are tt testdata cases.

The next tt lines each contain two positive integers nn and rr.

Output Format

Output tt lines, each containing one integer representing the answer.

3
3 5
3 6
3 7
3
1
-1

Hint

Constraints

Test Point ID tt nn rr
131 \sim 3 10\leqslant 10 105\leqslant 10^5 100\leqslant 100
464 \sim 6 100\leqslant 100 107\leqslant 10^7 1000\leqslant 1000
7107 \sim 10 104\leqslant 10^4 109\leqslant 10^9 104\leqslant 10^4

Translated by ChatGPT 5