Skip to content

Commit cf2485a

Browse files
committed
sqrt-decomposition
1 parent b0ddce8 commit cf2485a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef AFMT_SQRT_DECOMP
2+
#define AFMT_SQRT_DECOMP
3+
4+
#include <array>
5+
#include <vector>
6+
7+
template <class T>
8+
std::vector<std::array<T, 3>> sqrt_decomposit(T n) { // (l, r, v)
9+
std::vector<std::array<T, 3>> ans;
10+
for (T l = 1, r; l <= n; l = r + 1) {
11+
r = n / (n / l);
12+
ans.push_back({l, r, n / l});
13+
}
14+
return ans;
15+
}
16+
17+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/enumerate_quotients
2+
3+
#include "../../src/alfred/config/io-sync-off.hpp"
4+
#include "../../src/alfred/math/sqrt-decomposition.hpp"
5+
#include <iostream>
6+
7+
int main(int argc, char const *argv[]) {
8+
long long n;
9+
optimizeIO(), std::cin >> n;
10+
11+
auto res = sqrt_decomposit(n);
12+
std::reverse(res.begin(), res.end());
13+
14+
std::cout << res.size() << '\n';
15+
for (auto &[l, r, v] : res) {
16+
std::cout << v << " ";
17+
}
18+
return 0;
19+
}

0 commit comments

Comments
 (0)