0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 14:08:46 +00:00

B3871 [GESP202309 五级] 因数分解

https://www.luogu.com.cn/record/174741748
This commit is contained in:
Baoshuo Ren 2024-08-25 23:10:59 +08:00
parent 501093ba1b
commit 5550877018
Failed to extract signature

42
Luogu/B3871/B3871.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include <cmath>
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;
}