From 83c3851438ebbe9c79baf84da345daac974ed114 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 16 Nov 2022 20:53:58 +0800 Subject: [PATCH] =?UTF-8?q?P4446=20[AHOI2018=E5=88=9D=E4=B8=AD=E7=BB=84]?= =?UTF-8?q?=E6=A0=B9=E5=BC=8F=E5=8C=96=E7=AE=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/94275503 --- Luogu/P4446/P4446.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Luogu/P4446/P4446.cpp diff --git a/Luogu/P4446/P4446.cpp b/Luogu/P4446/P4446.cpp new file mode 100644 index 00000000..4198ea60 --- /dev/null +++ b/Luogu/P4446/P4446.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int t, p, primes[N]; +bool not_prime[N]; +std::unordered_map map; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + for (int i = 2; i < N; i++) { + if (!not_prime[i]) primes[++p] = i; + + for (int j = 1; j <= p && primes[j] * i < N; j++) { + not_prime[primes[j] * i] = true; + + if (i % primes[j] == 0) break; + } + } + + for (int i = 1; i <= p; i++) { + long long x = primes[i]; + map[x * x * x] = primes[i]; + } + + cin >> t; + + while (t--) { + long long n, ans = 1; + + cin >> n; + + int m = std::sqrt(std::sqrt(n)); + + if (map.count(n)) { + cout << map[n] << endl; + + continue; + } + + for (int i = 1, x = primes[i]; i <= p && x <= m && static_cast(x) * x * x <= n; x = primes[++i]) { + long long y = static_cast(x) * x * x; + + while (n % y == 0) { + ans *= x; + n /= y; + } + + while (n % x == 0) { + n /= x; + } + } + + if (map.count(n)) ans *= map[n]; + + cout << ans << endl; + } + + return 0; +}