Skip to content

Commit 29264ff

Browse files
committed
Enhanced sqrt-decomposition, added i128 iostream.
1 parent be9ef6e commit 29264ff

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/alfred/all

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "math/linear.hpp"
3131
#include "math/mod-int.hpp"
3232
#include "math/speed-of-light-power.hpp"
33+
#include "math/sqrt-decomposition.hpp"
3334
#include "math/utils.hpp"
3435

3536
#include "string/hashed-string.hpp"
@@ -57,4 +58,23 @@ inline void No(void) { std::cout << "No\n"; }
5758
inline void YES_NO(bool cond) { cond ? YES() : NO(); }
5859
inline void Yes_No(bool cond) { cond ? Yes() : No(); }
5960

61+
std::ostream &operator<<(std::ostream &os, i128 n) {
62+
std::string s;
63+
while (n) {
64+
s += '0' + n % 10;
65+
n /= 10;
66+
}
67+
std::reverse(s.begin(), s.end());
68+
return os << s;
69+
}
70+
71+
std::istream &operator>>(std::istream &is, i128 &n) {
72+
std::string s;
73+
is >> s;
74+
for (auto &c : s) {
75+
n = n * 10 + (c - '0');
76+
}
77+
return is;
78+
}
79+
6080
#endif // ALFRED_ALL

src/alfred/math/sqrt-decomposition.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
template <class T>
88
std::vector<std::array<T, 3>> sqrt_decomposit(T n) { // (l, r, v)
99
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});
10+
for (T l = 1, r, v; l <= n; l = r + 1) {
11+
v = n / l, r = n / v;
12+
ans.push_back({l, r, v});
1313
}
1414
return ans;
1515
}

0 commit comments

Comments
 (0)