-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdivisor.cpp
More file actions
52 lines (40 loc) · 992 Bytes
/
Copy pathdivisor.cpp
File metadata and controls
52 lines (40 loc) · 992 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// 正の整数 n の約数を列挙する, O(√n)
//
// verified
// ABC 112 D - Partition
// https://beta.atcoder.jp/contests/abc112/tasks/abc112_d
//
/*
n の約数を返す
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long> calc_divisor(long long n) {
vector<long long> res;
for (long long i = 1LL; i*i <= n; ++i) {
if (n % i == 0) {
res.push_back(i);
long long j = n / i;
if (j != i) res.push_back(j);
}
}
sort(res.begin(), res.end());
return res;
}
//------------------------------//
// Examples
//------------------------------//
int main() {
long long N, M;
cin >> N >> M;
vector<long long> div = calc_divisor(M);
// M の約数 d であって、d * N <= M となる最大の d を求める
long long res = 1;
for (auto d : div) {
if (d * N <= M) res = max(res, d);
}
cout << res << endl;
}