版本比较
Number Theory Half Family Bucket
正文
增加 99 行删除 3 行
373 行未改动全部展开37437537637737837837938038138250 行未改动433434435436437437438439440441442442443444445446103 行未改动全部展开550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654373 行未改动全部展开#define int long long#define sor(i, l, r) for (int i = l; i <= r; ++i)#define ros(i, r, l) for (int i = r; i >= l; --i)using namespace std;namespace Revitalize {namespace Eaux { constexpr const int N = 5e5 + 5, P = 998244353; int T, n; void write(__int128 x) { if (x >= 10)50 行未改动 write(DIVCNT(n)); putchar('\n'); } }} // namespace Revitalize} // namespace Eauxsigned main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return Revitalize::work(), 0; return Eaux::work(), 0;}```
### III. What's More...103 行未改动全部展开转移的起点即为向量 $(1,0)$,和 $(1,1)$。
剩下的部分与上一题完全一致,代码也不难写。
```cpp#include <bits/stdc++.h>#define int long long#define sor(i, l, r) for (int i = l; i <= r; ++i)#define ros(i, r, l) for (int i = r; i >= l; --i)using namespace std;namespace IO { /* ... */}using IO::pc;using IO::print;using IO::read;namespace Eaux { constexpr const int N = 5e5 + 5, P = 998244353; int T, n; struct vec { int x, y; __int128 pi, alp, bet; }; vector<vec> ddz; inline vec pushup(vec L, vec R) { return (vec){L.x + R.x, L.y + R.y, L.pi + R.pi + (__int128)L.x * R.y - 1, L.alp + R.alp + (__int128)L.x * R.pi + (((__int128)(L.x - 1) * L.x * R.y) >> 1) - L.x, L.bet + R.bet - (__int128)L.y * R.pi - (((__int128)((L.y << 1) + R.y + 1) * R.y * L.x) >> 1) + L.y}; } inline int Sqrt(int x) { int r = sqrtl((long double)x); while ((__int128)(r + 1) * (r + 1) <= x) ++r; while ((__int128)r * r > x) --r; return r; } void AFS3(int n) { __int128 ans = 0; int m = Sqrt(n); int x = n / m, y = m + 1; ddz.clear(); ddz.push_back((vec){1, 0, 2, 1, 0}); ddz.push_back((vec){1, 1, 3, 1, -2}); while (1) { vec L = ddz.back(); ddz.pop_back(); while ((__int128)(x + L.x) * (y - L.y) > n) { ans += (((__int128)(x - 1) * x * L.y) >> 1) + L.alp + (__int128)x * L.pi - x - (x + L.x); ans += (((__int128)((y << 1) - L.y - 1) * L.y * (x - 1)) >> 1) + L.bet + (__int128)y * L.pi - y - (y - L.y); x += L.x; y -= L.y; } if (y <= 2097151 && y * y * y <= n) break; vec R = ddz.back(); while ((__int128)(x + R.x) * (y - R.y) <= n) { L = R; ddz.pop_back(); R = ddz.back(); } while (1) { vec mid = pushup(L, R); if ((__int128)(x + mid.x) * (y - mid.y) > n) { R = mid; ddz.push_back(mid); } else { if ((__int128)(x + mid.x) * (x + mid.x) * R.y >= (__int128)n * R.x) break; else L = mid; } } } sor(i, 1, y - 1) { int k = n / i; ans += (__int128)i * k + (((__int128)k * ((__int128)k + 1)) >> 1); } ans -= ((__int128)m * m * (m + 1)) >> 1; ans -= ((__int128)n * ((__int128)n + 1)) >> 1; print(ans); } inline void work() { read(T); while (T--) { read(n); AFS3(n); pc('\n'); } }} // namespace Eauxsigned main() { return Eaux::work(), 0;}
```
# References[1] Alcántara D, Blanco M, Criado F, Santos F. On the convex hull of integer points above the hyperbola[EB/OL]. arXiv:2501.19193, 2025. https://arxiv.org/abs/2501.19193. [2] Li D. Computing the divisor summatory function in $N^{9/28+o(1)}$[EB/OL]. arXiv:2609.29949, 2026. https://arxiv.org/abs/2609.29949. [3] OI-wiki. Stern–Brocot tree[EB/OL]. https://oi-wiki.org/math/number-theory/stern-brocot/. [4] Rigel. SP26073 DIVCNT1 - Counting Divisors[EB/OL]. 洛谷专栏, 2025-12-19. https://www.luogu.com.cn/article/80p3nyn6.