1
0
Fork 0

Update include.hh

Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
subcrip 2024-05-09 11:25:34 +08:00
parent 5d28967e3f
commit d20bb2ed65
1 changed files with 18 additions and 0 deletions

View File

@ -24,6 +24,7 @@ using ull = uint64_t;
#else #else
using ll = long long; using ll = long long;
using ull = unsigned long long; using ull = unsigned long long;
using ld = long double;
#endif #endif
using int128 = __int128_t; using int128 = __int128_t;
using uint128 = __uint128_t; using uint128 = __uint128_t;
@ -236,6 +237,7 @@ ll inverse(ll a, ll b) {
} }
vector<tuple<int, int, ll>> decompose(ll x) { vector<tuple<int, int, ll>> decompose(ll x) {
// return (factor, count, factor ** count)
vector<tuple<int, int, ll>> res; vector<tuple<int, int, ll>> res;
for (int i = 2; i * i <= x; i++) { for (int i = 2; i * i <= x; i++) {
if (x % i == 0) { if (x % i == 0) {
@ -251,6 +253,22 @@ vector<tuple<int, int, ll>> decompose(ll x) {
return res; return res;
} }
vector<pii> decompose_prime(int N) {
// return (factor, count)
vector<pii> result;
for (int i = 2; i * i <= N; i++) {
if (N % i == 0) {
int cnt = 0;
while (N % i == 0) N /= i, ++cnt;
result.emplace_back(i, cnt);
}
}
if (N != 1) {
result.emplace_back(N, 1);
}
return result;
}
/* string algorithms */ /* string algorithms */
vector<int> calc_next(string t) { // pi function of t vector<int> calc_next(string t) { // pi function of t
int n = (int)t.length(); int n = (int)t.length();