From 5550877018b0143af8f1f8e5b13a15ca21e1e70e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 25 Aug 2024 23:10:59 +0800 Subject: [PATCH] =?UTF-8?q?B3871=20[GESP202309=20=E4=BA=94=E7=BA=A7]=20?= =?UTF-8?q?=E5=9B=A0=E6=95=B0=E5=88=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/174741748 --- Luogu/B3871/B3871.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Luogu/B3871/B3871.cpp diff --git a/Luogu/B3871/B3871.cpp b/Luogu/B3871/B3871.cpp new file mode 100644 index 00000000..05797eaa --- /dev/null +++ b/Luogu/B3871/B3871.cpp @@ -0,0 +1,42 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +long long n; +bool flag; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + long long x = n; + + for (long long i = 2; i <= std::sqrt(n); i++) { + if (x % i == 0) { + int cnt = 0; + + while (x % i == 0) x /= i, cnt++; + + if (flag) cout << " * "; + else flag = true; + + if (cnt > 1) { + cout << i << '^' << cnt; + } else { + cout << i; + } + } + } + + if (x > 1) { + if (flag) cout << " * "; + cout << x; + } + + return 0; +}