-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18_boj_11653.cpp
More file actions
46 lines (38 loc) · 766 Bytes
/
18_boj_11653.cpp
File metadata and controls
46 lines (38 loc) · 766 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 10000000
using namespace std;
int arr[MAX+1]={0,}; // 0 => prime, 1 => composite
void eratosthenes() {
for (int i=2; i*i<=MAX; i++) {
if( arr[i]==0 ) {
for (int j=i*i; j<=MAX; j+=i) {
arr[j]=1;
}
}
}
}
int n;
int main() {
eratosthenes();
// for (int i=0; i<=MAX; i++) {
// printf("%d ", arr[i]);
// }
scanf("%d", &n);
int iter=n;
for (int i=2; i<=iter; i++) {
if (arr[i]==1) {
continue;
}
while (n%i == 0) {
printf("%d\n",i);
n=n/i;
}
if (n==1) {
break;
}
}
return 0;
}