Two Divisors
题面翻译
题意翻译
给出两个正整数 a , b a, b a,b ( 1 ≤ a < b ≤ 1 0 9 ) (1 \le a < b \le 10^9) (1≤a<b≤109),求出 x x x,使得 a a a 与 b b b 分别是 x x x 的最大的两个不等于 x x x 的因数。保证存在满足条件的 x x x 且 1 ≤ x ≤ 1 0 9 1 \le x \le 10^9 1≤x≤109。 共 t t t 组数据 ( 1 ≤ t ≤ 1 0 4 , ∑ n ≤ 1 0 5 ) (1 \le t \le 10^4, \sum n \le 10^5) (1≤t≤104,∑n≤105),对于每组数据输出满足条件的 x x x;若有多个,输出任一即可。
题目描述
A certain number 1 ≤ x ≤ 1 0 9 1 \le x \le 10^9 1≤x≤109 is chosen. You are given two integers a a a and b b b , which are the two largest divisors of the number x x x . At the same time, the condition 1 ≤ a < b < x 1 \le a < b < x 1≤a<b<x is satisfied.
For the given numbers a a a , b b b , you need to find the value of x x x .
† ^{\dagger} † The number y y y is a divisor of the number x x x if there is an integer k k k such that x = y ⋅ k x = y \cdot k x=y⋅k .
输入格式
Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104 ) — the number of test cases. Then follows the description of the test cases.
The only line of each test cases contains two integers a a a , b b b ( 1 ≤ a < b ≤ 1 0 9 1 \le a < b \le 10^9 1≤a<b≤109 ).
It is guaranteed that a a a , b b b are the two largest divisors for some number 1 ≤ x ≤ 1 0 9 1 \le x \le 10^9 1≤x≤109 .
输出格式
For each test case, output the number x x x , such that a a a and b b b are the two largest divisors of the number x x x .
If there are several answers, print any of them.
样例 #1
样例输入 #1
8
2 3
1 2
3 11
1 5
5 10
4 6
3 9
250000000 500000000
样例输出 #1
6
4
33
25
20
12
27
1000000000
提示说明
For the first test case, all divisors less than 6 6 6 are equal to [ 1 , 2 , 3 ] [1, 2, 3] [1,2,3] , among them the two largest will be 2 2 2 and 3 3 3 .
For the third test case, all divisors less than 33 33 33 are equal to [ 1 , 3 , 11 ] [1, 3, 11] [1,3,11] , among them the two largest will be 3 3 3 and 11 11 11 .
For the fifth test case, all divisors less than 20 20 20 are equal to [ 1 , 2 , 4 , 5 , 10 ] [1, 2, 4, 5, 10] [1,2,4,5,10] , among them the two largest will be 5 5 5 and 10 10 10 .
For the sixth test case, all divisors less than 12 12 12 are equal to [ 1 , 2 , 3 , 4 , 6 ] [1, 2, 3, 4, 6] [1,2,3,4,6] , among them the two largest will be 4 4 4 and 6 6 6 .
代码内容
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
if(!b) return a;
else return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
void solve()
{
ll a,b;
cin>>a>>b;
if(b%a==0) cout<<b*b/a<<endl;
else cout<<lcm(a,b)<<endl;
}
int main()
{
ll t;
cin>>t;
while(t--) solve();
return 0;
}