我是靠谱客的博主 精明舞蹈,最近开发中收集的这篇文章主要介绍D. Buying Shovels,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Problem - D - Codeforces

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

Copy

5
8 7
8 1
6 10
999999733 999999732
999999733 999999733

output

Copy

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.

思路:注意只能选择一种类型的包裹,所有会被这个包裹整除,也就是求出在k范围内的约数即可,但是简单暴力肯定tle,所以可以用试除法求,质数只能被自身和1整除,所以如果是质数只要输出本身即可

#include<iostream>
using namespace std;
typedef long long ll; 
int t;
ll n,k;
bool is_prime(ll n)
{
    if(n==1)return false;
    if(n==2)return true;
    for(int i=2;i<=n/i;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}
ll get_disv_max(ll n,ll k)
{
    ll maxx=0;
    for(ll i=1;i<=n/i;i++)
    {
        if(n%i==0)
        {
            if(i<=k)
            maxx=max(maxx,i);
            if(n/i<=k)
            maxx=max(maxx,n/i);
        }
    }
    return maxx;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld %lld",&n,&k);
        if(n<=k)cout<<1<<endl;
        else//只能选择同一种包裹,素数只能被1整除
        {
            if(is_prime(n))
            cout<<n<<endl;
            else 
            {
                ll ans=get_disv_max(n,k);
                cout<<n/ans<<endl;
            }
        }
    }
}

最后

以上就是精明舞蹈为你收集整理的D. Buying Shovels的全部内容,希望文章能够帮你解决D. Buying Shovels所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(29)

评论列表共有 0 条评论

立即
投稿
返回
顶部