首页 > 其他 > 详细

D. Buying Shovels

时间:2020-05-26 11:05:12      阅读:111      评论:0      收藏:0      [点我收藏+]

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 (1ik1≤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 (1t1001≤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 (1n1091≤n≤109) and kk (1k1091≤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.

地址:http://codeforces.com/contest/1360/problem/D

思路:for 循环到 40000(40000 * 40000 > 1e9)

int main()
{
    int t ;
    cin >> t;
    while (t--)
    {
        ll n, k;
        ll ans = 0;

        cin >> n >> k;
        for (ll i = 1; i <= 40000; i++)
        {
            if (n % i == 0)
            {
                if (i <= k) ans = max(ans, i);
                if (n / i <= k) ans = max(ans, n / i);
            }
        }
        cout << n / ans << endl;
    }
    return 0;
}

 

D. Buying Shovels

原文:https://www.cnblogs.com/yin101/p/12963816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!