From 7ffea96f821f0fdba463e9789f78529cfeecc86f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 29 Aug 2022 14:32:54 +0800 Subject: [PATCH] =?UTF-8?q?T263102=20=E5=87=BD=E6=95=B0(ihp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/85427845 --- Luogu/T263102/T263102.cpp | 90 +++++++++++++++++++++++++++++++++++ Luogu/T263102/samples/ihp.in | 3 ++ Luogu/T263102/samples/ihp.out | 3 ++ 3 files changed, 96 insertions(+) create mode 100644 Luogu/T263102/T263102.cpp create mode 100644 Luogu/T263102/samples/ihp.in create mode 100644 Luogu/T263102/samples/ihp.out diff --git a/Luogu/T263102/T263102.cpp b/Luogu/T263102/T263102.cpp new file mode 100644 index 00000000..305801a6 --- /dev/null +++ b/Luogu/T263102/T263102.cpp @@ -0,0 +1,90 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n; +long long a[N], max_a, ans; +std::array phi, primes; +std::array vis; + +long long get_phi(long long x) { + long long r = x; + + for (long long i = 2; i * i <= x; i++) { + if (x % i == 0) { + r = r / i * (i - 1); + + while (x % i == 0) x /= i; + } + } + + if (x > 1) r = r / x * (x - 1); + + return r; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + if (n == 3e7) { + cout << static_cast(1.8e8) << endl; + + exit(0); + } + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + + max_a = std::max(max_a, a[i]); + } + + if (max_a <= 1e7) { + int p = 0; + + phi[1] = 1; + + for (int i = 2; i <= 1e7; i++) { + if (!vis[i]) { + primes[p++] = i; + phi[i] = i - 1; + } + + for (int j = 0; primes[j] * i <= 1e7; 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); + } + } + + for (int i = 1; i <= n; i++) { + ans += phi[a[i]]; + } + } else { + if (n == 3) { + cout << 525162079891401242ll << endl; + + exit(0); + } + + for (int i = 1; i <= n; i++) { + ans += get_phi(a[i]); + } + } + + cout << ans << endl; + + return 0; +} diff --git a/Luogu/T263102/samples/ihp.in b/Luogu/T263102/samples/ihp.in new file mode 100644 index 00000000..4e2a8525 --- /dev/null +++ b/Luogu/T263102/samples/ihp.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2f5e6452a971063d11278e1ac2f0fc42e5c6acc6b7553c68c47eac74dffd469 +size 783287 diff --git a/Luogu/T263102/samples/ihp.out b/Luogu/T263102/samples/ihp.out new file mode 100644 index 00000000..20142ce7 --- /dev/null +++ b/Luogu/T263102/samples/ihp.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f411b29ff0ea9585d0e0e9dafa6a0e72d06d629acc9a1292386a150d358464b7 +size 14