YouKn0wWho has two even integers xx and yy. Help him to find an integer nn such that 1≤n≤2⋅10181≤n≤2⋅1018 and nmodx=ymodnnmodx=ymodn. Here, amodbamodb denotes the remainder of aa after division by bb. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

Input

The first line contains a single integer tt (1≤t≤1051≤t≤105)  — the number of test cases.

The first and only line of each test case contains two integers xx and yy (2≤x,y≤1092≤x,y≤109, both are even).

Output

For each test case, print a single integer nn (1≤n≤2⋅10181≤n≤2⋅1018) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

Example

input

Copy

4
4 8
4 2
420 420
69420 42068

output

Copy

4
10
420
9969128

Note

In the first test case, 4mod4=8mod4=04mod4=8mod4=0.

In the second test case, 10mod4=2mod10=210mod4=2mod10=2.

In the third test case, 420mod420=420mod420=0420mod420=420mod420=0.

思路:除余时一定要注意前后的大小关系,非常重要!

非常明显除余就是小的数到大的数的距离(差距)

n%x==y%n 说明x到n 的距离与y到n的距离相等,但一定要考虑x,y的大小关系;

x>y时就有x在y的后方,那么y到x的差距就是(x-y)此时要想满足等式,此时的关系就非常微妙了,可以假设n=x+y,y%(x+y)=y,即(x+y)%x=y,=y%x ,要等于y 就有x>y,便满足关系

#include <iostream>
#include <algorithm>using namespace std;//n%x 与y%n 相等,说明相隔 距离相等int main()
{int t;cin>>t;while(t--){int x,y;cin>>x>>y;if(x>y){cout<<(x+y)<<endl;}else{cout<<y-(y%x)/2<<endl;}}return 0;
}

Moderate Modular Mode相关推荐

  1. Codeforces-1604 D: Moderate Modular Mode

    Codeforces 1604D: Moderate Modular Mode 题目 题目传送门:codeforces 1604D 题目截图 样例描述 题目大意   给定两个偶数 x x x 和 y ...

  2. Moderate Modular Mode %,取模运算性质,数轴,思维

    题意: 给两个偶数x和y,找到n满足n%x == y%n 思路: 分类找特殊情况.一般而言我们猜测n%x=y%n这个式子的值是0或者y之类比较特殊的,然后再猜测n的表达式 x==y,则n取x x> ...

  3. CF1603B Moderate Modular Mode

    题目大意 给定两个偶数 x , y x,y x,y. 求一个 n ∈ [ 1 , 2 × 1 0 18 ] n \in [1,2\times10^{18}] n∈[1,2×1018] 满足 n m o ...

  4. Codeforces1603 B. Moderate Modular Mode(数学)

    题意: 解法: n % x = y % n 优 先 考 虑 结 果 为 特 殊 值 , 如 0 和 y . n % x = y % n = 0 , 当 x = = y 时 , n 取 x 成 立 . ...

  5. codeforces round #752

    题目链接 A. Era typedef long long ll;void solve(){ll n;scanf("%lld",&n);ll ans = 0;ll x,y; ...

  6. Codeforces Round #752 (Div. 2)部分题解(A ~ D)

    A. Era (模拟) 比赛链接:https://codeforces.com/problemset/problem/1604/A 题目大意 给出长度为 n n n的数组 a a a,每次我们可以任意 ...

  7. Blender模块化建筑环境地形场景制作视频教程 Creating modular environments

    Blender模块化建筑环境地形场景制作视频教程 Creating modular environments Blender模块化建筑环境地形场景制作视频教程 Creating modular env ...

  8. Modular Multiplicative Inverse(模乘逆元)

    计算模乘逆元原理上有四种方法: 1.暴力算法 2.扩展欧几里得算法 3.费尔马小定理 4.欧拉定理 模乘逆元定义:满足 ab≡1(mod m),称b为a模乘逆元.以下是有关概念以及四种方法及程序. 文 ...

  9. B - Modular Inverse

    The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x ...

最新文章

  1. 测试总监7天整理的那些高频而真实的软件测试面试题,速来get
  2. iOS开发者有价值的工具集
  3. python正则表达式匹配模式屠夫之桥_Python 编程快速上手 第 7章 模式匹配与正则表达式...
  4. 话里话外:“按单制造”的业务特点(一)
  5. java定时器小程序_【微信小程序】使用setTimeout试试定时器
  6. flink知识点总结
  7. 【学堂在线数据挖掘:理论方法笔记】第一天(3.17)
  8. mysql开启事务并锁表_MySQL:如何锁定表并启动事务?
  9. 英语 没有听懂对方说什么 怎么说
  10. 【攻防世界 | WP】CAT
  11. 2017年ACM第八届山东省赛I题: Parity check(判断 第n项斐波那契数列奇偶性)
  12. 给大家分享一下指纹挂锁的方案
  13. 操作系统中的虚拟内存详解
  14. C++ Reference: Standard C++ Library reference: C Library: cstdio: printf
  15. npm WARN webpack-cli@3.3.11 requires a peer of webpack@4.x.x but none is installed. You must install
  16. JS中怎样使用Date对象加减日期
  17. H5/APP客服端源码/uniapp在线客服系统源码开源了,全源码代码解读及发行安装教程...
  18. vue通过点击按钮弹出新窗口打开html文件
  19. 亚马逊、Lazada卖家如何做测评自养号和提升店铺流量
  20. 人工智能、机器学习概述

热门文章

  1. 面试续与如何做自己的职业规划
  2. 深圳高新技术企业补贴政策及有何好处,补贴30万
  3. linux虚拟光驱挂载教程,Linux操作系统下虚拟光驱(iso)的挂载
  4. AStar寻路算法的Python实现
  5. apollo如何添加第三方库,以pylon为例
  6. android+蓝牙遥控器,一种通过蓝牙遥控安卓设备的方法与流程
  7. 附件怎么插到公众号里
  8. windows11 文档背景设置护眼色
  9. 阿里云云原生数据湖体系全解读——元原生数据湖体系
  10. 范型方法 范型参数 范型返回值