#CF2009E. Klee's SUPER DUPER LARGE Array!!!

    ID: 6919 传统题 1000ms 256MiB 尝试: 1 已通过: 1 难度: 10 上传者: 标签>二分数学三分CodeforcesCodeforces Round 971(Div4)Div4ECF2009E1400

Klee's SUPER DUPER LARGE Array!!!

题目描述

题目大意

你将得到一个长度为 nn 的序列 a=[k,k+1,k+2,,k+n1]a=[k,k+1,k+2,\dots, k+n-1],请求出 SS 的值,其中

$$S=\min\limits_{1\le x\le n}|(\sum\limits_{i=1}^x a_i)-(\sum\limits_{i=x+1}^n a_i)|$$

输入格式

本题存在多组测试数据。第一行为一个正整数 TT1T1041\le T\le 10^4),表示数据组数。对于每组数据分别给出用空格隔开的两个整数 nnkk2n,k1092\le n,k\le 10^9)。

输出格式

对于每组数据,输出一行一个整数 SS

样例

4
2 2
7 2
5 3
1000000000 1000000000
1
5
1
347369930

样例说明

In the first sample, a=[2,3] a = [2, 3] . When i=1 i = 1 is chosen, x=23=1 x = |2-3| = 1 . It can be shown this is the minimum possible value of x x .

In the third sample, a=[3,4,5,6,7] a = [3, 4, 5, 6, 7] . When i=3 i = 3 is chosen, x=3+4+567=1 x = |3 + 4 + 5 - 6 - 7| = 1 . It can be shown this is the minimum possible value of x x .

来源

Codeforces 2009E,英文题名 Klee's SUPER DUPER LARGE Array!!!。