• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

A题题解

开发技术 开发技术 6天前 5次浏览

题目:

  

We have a point AA with coordinate x=nx=n on OXOX-axis. We’d like to find an integer point BB (also on OXOX-axis), such that the absolute difference between the distance from OO to BB and the distance from AA to BB is equal to kk.

A题题解The description of the first test case.

Since sometimes it’s impossible to find such point BB, we can, in one step, increase or decrease the coordinate of AA by 11. What is the minimum number of steps we should do to make such point BB exist?

Input

The first line contains one integer tt (1t60001≤t≤6000) — the number of test cases.

The only line of each test case contains two integers nn and kk (0n,k1060≤n,k≤106) — the initial position of point AA and desirable absolute difference.

Output

For each test case, print the minimum number of steps to make point BB exist.

Example

Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
题目要求距离差为K最少步数,首先如果a等于k就不用移动,b可为a点,a小于k,就是k-a步,因为这时a移动到k,b可为0,最短。
如果a大于k,就判断a-k的差,为偶就不用移动,因为如果两数相减为偶,两数就只可能是1.奇奇2.偶偶,如果a为奇,中间可找到
任何一个点,相减使其为小于等于a的奇数,如果a为偶,中间可找到任何一个点,相减使其为小于等于a的偶数。
如果a-k的差为奇,那么a移动一位就变成差为偶的情况
代码:
#include<stdio.h>
int main(){
    int n,a,b;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&a,&b);
        if(a>b){
            if((a-b)%2==0)printf("%dn",0);
            else printf("%dn",1);
        }
        else if(a<b)printf("%dn",b-a);
        else printf("0n");
    }
    return 0;
} 

 


程序员灯塔
转载请注明原文链接:A题题解
喜欢 (0)