Moderate Modular Mode
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相关推荐
- Codeforces-1604 D: Moderate Modular Mode
Codeforces 1604D: Moderate Modular Mode 题目 题目传送门:codeforces 1604D 题目截图 样例描述 题目大意 给定两个偶数 x x x 和 y ...
- Moderate Modular Mode %,取模运算性质,数轴,思维
题意: 给两个偶数x和y,找到n满足n%x == y%n 思路: 分类找特殊情况.一般而言我们猜测n%x=y%n这个式子的值是0或者y之类比较特殊的,然后再猜测n的表达式 x==y,则n取x x> ...
- 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 ...
- Codeforces1603 B. Moderate Modular Mode(数学)
题意: 解法: n % x = y % n 优 先 考 虑 结 果 为 特 殊 值 , 如 0 和 y . n % x = y % n = 0 , 当 x = = y 时 , n 取 x 成 立 . ...
- codeforces round #752
题目链接 A. Era typedef long long ll;void solve(){ll n;scanf("%lld",&n);ll ans = 0;ll x,y; ...
- Codeforces Round #752 (Div. 2)部分题解(A ~ D)
A. Era (模拟) 比赛链接:https://codeforces.com/problemset/problem/1604/A 题目大意 给出长度为 n n n的数组 a a a,每次我们可以任意 ...
- Blender模块化建筑环境地形场景制作视频教程 Creating modular environments
Blender模块化建筑环境地形场景制作视频教程 Creating modular environments Blender模块化建筑环境地形场景制作视频教程 Creating modular env ...
- Modular Multiplicative Inverse(模乘逆元)
计算模乘逆元原理上有四种方法: 1.暴力算法 2.扩展欧几里得算法 3.费尔马小定理 4.欧拉定理 模乘逆元定义:满足 ab≡1(mod m),称b为a模乘逆元.以下是有关概念以及四种方法及程序. 文 ...
- B - Modular Inverse
The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x ...
最新文章
- 测试总监7天整理的那些高频而真实的软件测试面试题,速来get
- iOS开发者有价值的工具集
- python正则表达式匹配模式屠夫之桥_Python 编程快速上手 第 7章 模式匹配与正则表达式...
- 话里话外:“按单制造”的业务特点(一)
- java定时器小程序_【微信小程序】使用setTimeout试试定时器
- flink知识点总结
- 【学堂在线数据挖掘:理论方法笔记】第一天(3.17)
- mysql开启事务并锁表_MySQL:如何锁定表并启动事务?
- 英语 没有听懂对方说什么 怎么说
- 【攻防世界 | WP】CAT
- 2017年ACM第八届山东省赛I题: Parity check(判断 第n项斐波那契数列奇偶性)
- 给大家分享一下指纹挂锁的方案
- 操作系统中的虚拟内存详解
- C++ Reference: Standard C++ Library reference: C Library: cstdio: printf
- npm WARN webpack-cli@3.3.11 requires a peer of webpack@4.x.x but none is installed. You must install
- JS中怎样使用Date对象加减日期
- H5/APP客服端源码/uniapp在线客服系统源码开源了,全源码代码解读及发行安装教程...
- vue通过点击按钮弹出新窗口打开html文件
- 亚马逊、Lazada卖家如何做测评自养号和提升店铺流量
- 人工智能、机器学习概述