Two Divisors

Two Divisors

题面翻译

题意翻译

给出两个正整数 a , b a, b a,b ( 1 ≤ a < b ≤ 1 0 9 ) (1 \le a < b \le 10^9) (1a<b109),求出 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 1x109。 共 t t t 组数据 ( 1 ≤ t ≤ 1 0 4 , ∑ n ≤ 1 0 5 ) (1 \le t \le 10^4, \sum n \le 10^5) (1t104,n105),对于每组数据输出满足条件的 x x x;若有多个,输出任一即可。

题目描述

A certain number 1 ≤ x ≤ 1 0 9 1 \le x \le 10^9 1x109 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 1a<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=yk .

输入格式

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 1t104 ) — 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 1a<b109 ).

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 1x109 .

输出格式

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值