D - Buying Shovels CodeForces - 1360D

Polycarp wants to buy exactly nn shovels. The shop sells packages with shovels. The store has kk types of packages: the package of the ii-th type consists of exactly ii shovels (1≤i≤k1≤i≤k). The store has an infinite number of packages of each type.

Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly nn shovels?

For example, if n=8n=8 and k=7k=7, then Polycarp will buy 22 packages of 44 shovels.

Help Polycarp find the minimum number of packages that he needs to buy, given that he:

  • will buy exactly nn shovels in total;
  • the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 11 to kk, inclusive.

Input

The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases in the input. Then, tt test cases follow, one per line.

Each test case consists of two positive integers nn (1≤n≤1091≤n≤109) and kk (1≤k≤1091≤k≤109) — the number of shovels and the number of types of packages.

Output

Print tt answers to the test cases. Each answer is a positive integer — the minimum number of packages.

Example

Input

5
8 7
8 1
6 10
999999733 999999732
999999733 999999733

Output

2
8
1
999999733
1

Note

The answer to the first test case was explained in the statement.

In the second test case, there is only one way to buy 88 shovels — 88 packages of one shovel.

In the third test case, you need to buy a 11 package of 66 shovels.

 

(真的,在我看到题解之前,我没想到会这么水的,果然还是我太菜了,居然只会暴力输出然后导致超时,苏菜菜)

题意:T组输入,每组给出n和m,求m范围内n的最大因子x,输出n/x。(哇,再次哭泣,我好菜啊)

题解:sqrt给n开根后缩小遍历范围,在这个范围内找出其最大因子即可求得n/x。此间注意因子是否在m范围内。太水了没办法再注释了,直接上代码吧。

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int t,n,k;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &k);
		int ans = 0;
		for(int i=1; i<=sqrt(n); i++){
			if(n%i == 0){
				if(i<=k)	ans = max(ans, i);
				if(n/i<=k)	ans = max(ans, n/i);
			}
		}
		printf("%d\n", n/ans);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值