-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFACTCG2.cpp
33 lines (33 loc) · 828 Bytes
/
FACTCG2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Ivan Carvalho
// Solution to https://www.spoj.com/problems/FACTCG2/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 2;
int biggest[MAXN];
int main() {
for (int i = 2; i < MAXN; i++) {
if (biggest[i] != 0) continue;
biggest[i] = i;
for (int j = i; j < MAXN; j += i) biggest[j] = i;
}
int n;
while (scanf("%d", &n) != EOF) {
vector<int> resp;
while (n != 1) {
resp.push_back(biggest[n]);
n /= biggest[n];
}
resp.push_back(1);
reverse(resp.begin(), resp.end());
int primeiro = 0;
for (int i : resp) {
if (primeiro)
printf(" x ");
else
primeiro = 1;
printf("%d", i);
}
printf("\n");
}
return 0;
}