From 61b9f3590405e815d66618acb241700ce3bb71e9 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 29 May 2022 18:44:10 +0800 Subject: [PATCH] =?UTF-8?q?T243086=20=E6=9C=80=E7=AE=80=E5=88=86=E6=95=B0?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/76645289 --- Luogu/T243086/T243086.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Luogu/T243086/T243086.cpp diff --git a/Luogu/T243086/T243086.cpp b/Luogu/T243086/T243086.cpp new file mode 100644 index 00000000..9726471b --- /dev/null +++ b/Luogu/T243086/T243086.cpp @@ -0,0 +1,43 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int n, p, primes[10000005], phi[10000005]; +bool vis[10000005]; +long long ans; + +void get_eulers(int n) { + phi[1] = 1; + for (int i = 2; i <= n; i++) { + if (!vis[i]) { + primes[p++] = i; + phi[i] = i - 1; + } + for (int j = 0; primes[j] * i <= n; j++) { + vis[primes[j] * i] = true; + if (i % primes[j] == 0) { + phi[primes[j] * i] = phi[i] * primes[j]; + break; + } + phi[primes[j] * i] = phi[i] * (primes[j] - 1); + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + get_eulers(n); + + for (int i = 2; i <= n; i++) { + ans += phi[i]; + } + + cout << ans << endl; + + return 0; +}