forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1360D.cpp
34 lines (28 loc) · 801 Bytes
/
1360D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
short t;
scanf("%hd", &t);
while (t--) {
LL n, k;
scanf("%lld", &n);
scanf("%lld", &k);
LL minPkg = LLONG_MAX;
if (n > k) {
// FIND THE MAX FACTOR, OPTIMIZE BY O(SQRT(N))
for (LL i = 2; i <= sqrt(n) && i <= k; i++) {
if ((n % i) == 0) {
LL ju;
if ((n / i) <= k) ju = min(i, n / i);
else ju = n / i;
minPkg = min(minPkg, ju);
}
}
if (minPkg == LLONG_MAX) minPkg = n;
}
else minPkg = 1;
printf("%lld\n", minPkg);
}
}