Buying Shovels
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
找出一个小于等于k且是n的最大因子的数,输出n/该因子数即可
代码如下
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int ans=0;
for(int j=1;j*j<=n;j++){
if(n%j==0){
if(j<=k) ans=max(ans,j);
if(n/j<=k) ans=max(ans,n/j);
}
}
cout<<n/ans<<endl;
}
return 0;
}