日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Buying Shovels CodeForces - 1360D(数论+找因子)

發布時間:2023/12/4 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Buying Shovels CodeForces - 1360D(数论+找因子) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

想買n個鏟子,一共有k種包裝,第i種包裝里有i個鏟子(1<=i<=k),問如何才能正好買n個鏟子,要求買相同包裝的,而且買的包書數最少

題目:

Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1≤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 n shovels?

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

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

will buy exactly n 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 1 to k, inclusive.

Input

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

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

Output

Print t 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 8 shovels — 8 packages of one shovel.

In the third test case, you need to buy a 1 package of 6 shovels.

分析:

直接枚舉n的所有因子x,如果這個因子在1?k那么計算一下n/x,并取最小值

AC代碼:

#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; typedef long long ll; int t,n,m,ans; int main() {scanf("%d",&t);while(t--){ans=0;scanf("%d%d",&n,&m);for(int i=1;i<=sqrt(n);i++)if(n%i==0){if(i<=m)ans=max(ans,i);if(n/i<=m)ans=max(ans,n/i);}printf("%d\n",n/ans);}return 0; }

總結

以上是生活随笔為你收集整理的Buying Shovels CodeForces - 1360D(数论+找因子)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。