From cf82beddae1ed4e64655964344818fa592f3650c Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 17 Sep 2021 19:20:45 +0800 Subject: [PATCH] =?UTF-8?q?873.=20=E6=AC=A7=E6=8B=89=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/7779824/ --- AcWing/873/873.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 AcWing/873/873.cpp diff --git a/AcWing/873/873.cpp b/AcWing/873/873.cpp new file mode 100644 index 00000000..63d4e9ea --- /dev/null +++ b/AcWing/873/873.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int n, x; + +int phi(int x) { + int res = x; + for (int i = 2; i * i <= x; i++) { + if (x % i == 0) { + res = res / i * (i - 1); + while (x % i == 0) x /= i; + } + } + if (x > 1) res = res / x * (x - 1); + return res; +} + +int main() { + cin >> n; + while (n--) { + cin >> x; + cout << phi(x) << endl; + } + return 0; +}