[噼昂!]我他媽是大傻逼
阿新 • • 發佈:2021-11-01
\[\color{red}{\text{校長者,真神人也,左馬桶,右永神,會執利筆破邪炁,何人當之?}} \\
\begin{array}{|}
\hline
\color{pink}{\text{The principal is really a god}} \\
\color{pink}{\text{with a closestool on the left and Yongshen on the right}} \\
\color{pink}{\text{holding a sharp pen to pierce the truth}} \\
\color{pink}{\text{Who can resist him? }} \\
\hline
\end{array} \\
\begin{array}{|}
\hline
\color{green}{\text{校長は本當に神であり、左側にトイレ、右側にヨンシェンがあり}} \\
\color{green}{\text{鋭いペンを持って真実を突き刺している。誰が彼に抵抗できるだろうか? }} \\
\hline
\end{array} \\
\begin{array}{|}
\hline
\color{lightblue}{\text{Le principal est vraiment un dieu}} \\
\color{lightblue}{\text{avec des toilettes à gauche et Yongshen à droite}} \\
\color{lightblue}{\text{tenant un stylo pointu pour percer la vérité}} \\
\color{lightblue}{\text{Qui peut lui résister ? }} \\
\hline
\end{array} \\
\begin{array}{|}
\hline
\color{purple}{\text{Der Direktor ist wirklich ein Gott}} \\
\color{purple}{\text{mit einer Toilette links und Yongshen rechts}} \\
\color{purple}{\text{der einen spitzen Stift hält}} \\
\color{purple}{\text{um die Wahrheit zu durchdringen.}} \\
\color{purple}{\text{Wer kann ihm widerstehen? }} \\
\hline
\end{array} \\
\begin{array}{|}
\hline
\color{cyan}{\text{Principalis deus est, Yongshen a dextris cum latrina}} \\
\color{cyan}{\text{acuto stylo ad perforandum veritatem: quis resistet ei? }} \\
\hline
\end{array} \\
\color{red}{\text{對曰:“無人,狗欲當之,還請賜教!”}} \\
\newcommand\bra[1]{\left({#1}\right)}
\newcommand\Bra[1]{\left\{{#1}\right\}}
\newcommand\dx[0]{\text{dx}}
\newcommand\string[2]{\genfrac{\{}{\}}{0pt}{}{#1}{#2}}
\newcommand\down[2]{{#1}^{\underline{#2}}}
\newcommand\ddiv[2]{\left\lfloor\frac{#1}{#2}\right\rfloor}
\newcommand\udiv[2]{\left\lceil\frac{#1}{#2}\right\rceil}
\newcommand\lcm[0]{\operatorname{lcm}}
\newcommand\set[1]{\left\{{#1}\right\}}
\newcommand\ceil[1]{\left\lceil{#1}\right\rceil}
\newcommand\floor[1]{\left\lfloor{#1}\right\rfloor}
\]
.
壹、題目描述 ¶
定義 \(f(x)=\mu^2(x)x\),求
\[\sum_{i=1}^n f(i) \]資料範圍保證 \(n\le 10^{14}\).
貳、題解 ¶
考慮用小的數去篩大的數。顯然我們只需要用到 \(\sqrt n\) 以內的數了。設 \(S(i)=1+2+3+\cdots+i=\frac{i(i+1)}{2}\),利用 \(\mu\) 自身的容斥性就可以算出來答案是:
\[\begin{aligned} \sum_{i=1}^{\sqrt n}\mu(i)S\bra{\ddiv{n}{i^2}}\cdot i^2 \end{aligned} \]然後就完了,我他媽是大傻逼。時間複雜度可能在 \(\mathcal O(\sqrt n+T\sqrt[3]n)\)
叄、參考程式碼 ¶
# define your short # define coffin vector<your>() #include <bits/stdc++.h> using namespace std; namespace Elaina { #define rep(i, l, r) for (int i = l, i##_end_ = r; i <= i##_end_; ++i) #define drep(i, l, r) for (int i = l, i##_end_ = r; i >= i##_end_; --i) #define fi first #define se second #define Endl putchar('\n') template<class T> inline T fab(T x) { return x < 0? -x: x; } template<class T> inline void getmax(T& x, const T& rhs) { x = max(x, rhs); } template<class T> inline void getmin(T& x, const T& rhs) { x = min(x, rhs); } typedef unsigned usint; typedef long long ll; typedef unsigned long long ull; } // namespace Elaina using namespace Elaina; const int maxn = 1e7; int mu[maxn + 5], prime[maxn + 5], pcnt; ull pre[maxn + 5]; bool sie[maxn + 5]; inline void sieve() { mu[1] = 1, sie[1] = true; for (int i = 2; i <= maxn; ++i) { if (!sie[i]) prime[++pcnt] = i, mu[i] = -1; for (int j = 1; j <= pcnt && i * prime[j] <= maxn; ++j) { sie[i * prime[j]] = true; if (i % prime[j] == 0) { mu[i * prime[j]] = 0; break; } else mu[i * prime[j]] = -mu[i]; } } for (int i = 1; i <= maxn; ++i) pre[i] = pre[i - 1] + (ull)i * i * mu[i]; } inline ull S(ll x) { ull ret; if (x & 1) ret = (ull)((x + 1) >> 1) * x; else ret = (ull)(x >> 1) * (x + 1); return ret; } signed main() { cin.tie(NULL) -> sync_with_stdio(false); sieve(); int _; cin >> _; ll n; while (_--) { cin >> n; ull ans = 0; for (ll l = 1, r; l * l <= n; l = r + 1) { r = sqrt(n / (n / l / l)); if(n / r / r == n / l / l) ++r; if(n / r / r != n / l / l) --r; ans += 1ll * (pre[r] - pre[l - 1]) * S(n / l / l); } printf("%llu\n", ans); } return 0; }