Add Odd or Subtract Even

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given two positive integers a and b.

In one move, you can change a in the following way:

Choose any positive odd integer x (x>0) and replace a with a+x;

choose any positive even integer y (y>0) and replace a with a−y.

You can perform as many such operations as you want. You can choose the same numbers x and y in different moves.

Your task is to find the minimum number of moves required to obtain b from a. It is guaranteed that you can always obtain b from a.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases.

Then t test cases follow. Each test case is given as two space-separated integers a and b (1≤a,b≤109).

Output

For each test case, print the answer — the minimum number of moves required to obtain b from a if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain b from a.

Example

input

5

2 3

10 10

2 4

7 4

9 3

output

1

0

2

2

1

Note

In the first test case, you can just add 1.

In the second test case, you don’t need to do anything.

In the third test case, you can add 1 two times.

In the fourth test case, you can subtract 4 and add 1.

In the fifth test case, you can just subtract 6.

分差的奇偶性,和大小


#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{ int a,b,c;
cin>>a>>b;
if(a==b) cout<<0<<endl;
else if(a>b)
{
if((a-b)%2==0)cout<<1<<endl;
else cout<<2<<endl;
}
else { if((b-a)%2==0)cout<<2<<endl;
else cout<<1<<endl;
}
}
}

Codeforce 1311A Add Odd or Subtract Even的更多相关文章

  1. [CF1311A] Add Odd or Subtract Even

    Solution a<b, delta=odd, ans=1 a<b, delta=even, ans=2 a=b ans=0 a>b, delta=odd, ans=2 a> ...

  2. Codeforces Round #624 (Div. 3) A. Add Odd or Subtract Even(水题)

    You are given two positive integers aa and bb . In one move, you can change aa in the following way: ...

  3. deep_learning_Function_tf.add()、tf.subtract()、tf.multiply()、tf.div()

    tf.add().tf.subtract().tf.multiply().tf.div()函数介绍和示例 1. tf.add() 释义:加法操作 示例: x = tf.constant(2, dtyp ...

  4. codeforce 1188A1 Add on a Tree 树

    题意:给你一个树,有一种操作,选择两个叶子节点,然后把这两个叶子节点间的路径全部加或减一个值.问你给出的树上的每一条边经过若干次操作是否可以为任意值. 分析:画几个图后可以发现,如果树中存在一个点的度 ...

  5. Codeforces补题2020.2.28(Round624 Div 3)

    A.Add Odd or Subtract Even 签到题~ #include<bits/stdc++.h> using namespace std; int T; int a,b; i ...

  6. Codeforces Round #624 (Div. 3)(题解)

    A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...

  7. HDU 4919 Exclusive or 数学

    题意: 定义 \[f(n)=\sum\limits_{i=1}^{n-1}(i\oplus (n-i))\] 求\(f(n),n \leq 10^{500}\) 分析: 这个数列对应OEIS的A006 ...

  8. 缓冲区溢出利用——捕获eip的傻瓜式指南

    [译文] 摘要:为一个简单的有漏洞程序写一个简单的缓冲区溢出EXP,聚焦于遇到的问题和关键性的教训,提供详细而彻底的描述 内容表:1. I pity the fool, who can't smash ...

  9. [开源].NET数据库访问框架Chloe.ORM

    扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...

随机推荐

  1. go 内置函数

    一.什么是内置函数? 二.内置函数有哪些? 名称 说明 close 用于管道通信 len.cap len 用于返回某个类型的长度或数量(字符串.数组.切片.map 和管道):cap 是容量的意思,用于 ...

  2. linux升级python2.7到3.7.0

    1.下载python3.7.0压缩包在 wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz 2.解压缩 tar -zxvf Py ...

  3. web系统安全运营之基础- 基于DFA算法的高性能的敏感词,脏词的检测过滤算法类(c#).

    [概述]做好一个web系统的安全运维,除了常规的防注入,防入侵等,还有一个检测并过滤敏感词,脏词..  这件事做得不好,轻则导致一场投诉或纠纷,重则导致产品被勒令关闭停运. 废话少说,先看下代码,可以 ...

  4. Xcode自动注释插件:VVDocumenter-Xcode

    VVDocumenter-Xcode 是由 @onevcat 喵神开发的一个Xcode插件,其作用是在Xcode中输入"///"后自动生成规范的文档注释,的确非常好用而且实用. G ...

  5. AJ学IOS(01) UI之Hello World与加法计算器

    不多说,AJ分享,必须精品 这两个一个是HelloWorld(左边) 另一个是 加法计算器(右边)的截图. 先运行第一个 程序看看效果 1.打开Xcode(没有哦mac系统的没有xcode的帮你们默哀 ...

  6. Daily Scrum 1/6/2015

    Process: Zhaoyang: Complete the speech API test and do some UI upgrade. Yandong: Help zhaoyang to do ...

  7. 安全测试-WEB安全渗透测试基础知识(四)

    .4. HTTP标准 1.4.1. 报文格式 1.4.1.1. 请求报文格式 <method><request-URL><version> <headers& ...

  8. 在pytorch下使用tensorboardX(win10;谷歌浏览器;jupyter notebook)

    使用环境:win10 ,在jupyter notebook下运行 谷歌浏览器 1.环境安装 使用conda 安装,打开anacond powershell,输入pip install tensorbo ...

  9. python 异步 I/O

    如果你想了解异步编程,那么必然会涉及出许多相关概念. 堵塞/非堵塞 同步/异步 多进程/多线程/协程 为什么我要学习这个话,因为我想搞懂异步框架和异步接口的调用.所以,我的学习路线是这样的: 1.py ...

  10. Oracle数据库提权

    一.执行java代码 简介 oracle提权漏洞集中存在于PL/SQL编写的函数.存储过程.包.触发器中.oracle存在提权漏洞的一个重要原因是PL/SQL定义的两种调用权限导致(定义者权限和调用者 ...