题解 CF1360D 【Buying Shovels】
这题确实没什么好讲的= =
如果 \(k >= n\) 那么肯定是取 \(i == n\) 此时答案为 \(1\)
如果 \(k < n\) 就找出 \(n\) 小于 \(k\) 的最大因子
Rep(i, 1, sqrt(n)) {
if(n % i == 0 && i <= k) now = n / i;//如果i是因子,那么n/i也是因子,先把i存下来,防止k < sqrt(n)
if(n % i == 0 && n / i <= k) { flag = 1; printf("%d\n", i); break;}//因为是从头枚举的,所以i == n / i 时最大
#include <bits/stdc++.h>
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
using namespace std;
inline int read() {
register int x = 0, f = 1; register char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
signed main() { int T = read();
while(T --) { int n = read(), k = read(), now = -1, flag = 0;
if(k >= n) { puts("1"); continue;}
else {
Rep(i, 1, sqrt(n)) {
if(n % i == 0 && i <= k) now = n / i;
if(n % i == 0 && n / i <= k) { flag = 1; printf("%d\n", i); break;}
}
}
if(flag == 0) printf("%d\n", now != -1 ? now : n);
}
return 0;
}