B. Two Divisors

time limit per test

1 second

memory limit per test

256 megabytes

A certain number 1≤x≤109 is chosen. You are given two integers a and b, which are the two largest divisors of the number x. At the same time, the condition 1≤a<b<x is satisfied.

For the given numbers a, b, you need to find the value of x.

† The number y is a divisor of the number x if there is an integer k such that x=y⋅k.

Input

Each test consists of several test cases. The first line contains a single integer t (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, b (1≤a<b≤109).

It is guaranteed that a, b are the two largest divisors for some number 1≤x≤109.

Output

For each test case, output the number x, such that a and b are the two largest divisors of the number x.

If there are several answers, print any of them.

Example

Input

Copy


8

2 3

1 2

3 11

1 5

5 10

4 6

3 9

250000000 500000000

Output

Copy

6
4
33
25
20
12
27
1000000000

Note

For the first test case, all divisors less than 6 are equal to [1,2,3], among them the two largest will be 2 and 3.

For the third test case, all divisors less than 33 are equal to [1,3,11], among them the two largest will be 3 and 11.

For the fifth test case, all divisors less than 20 are equal to [1,2,4,5,10], among them the two largest will be 5 and 10.

For the sixth test case, all divisors less than 12 are equal to [1,2,3,4,6], among them the two largest will be 4 and 6.

3

解题说明:此题是一道数学题,为了保证a和b是x的最大公约数,找规律能发现按情况分类查找,当a为1,则x为b*b,如果b能被a整除,x = b * (b / a);否则就从2开始遍历,直到x能整除a。

#include<stdio.h>
int main()
{
	int t, n, a, b, x, i;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d %d", &a, &b);
		if (a == 1)
		{
			x = b * b;
		}
		else if (b % a == 0)
		{
			x = b * (b / a);
		}
		else
		{
			for (i = 2; i <= b; i++)
			{
				x = i * b;
				if (x % a == 0)
				{
					break;
				}
			}
		}
		printf("%d\n", x);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值