forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12852.cpp
More file actions
35 lines (33 loc) · 669 Bytes
/
12852.cpp
File metadata and controls
35 lines (33 loc) · 669 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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/da0497aabb26436c9ae613785cb439f7
#include <bits/stdc++.h>
using namespace std;
int d[1000005];
int pre[1000005];
int n;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
d[1] = 0;
for(int i = 2; i <= n; i++){
d[i] = d[i-1] + 1;
pre[i] = i-1;
if(i%2 == 0 && d[i] > d[i/2] + 1){
d[i] = d[i/2] + 1;
pre[i] = i/2;
}
if(i%3 == 0 && d[i] > d[i/3] + 1){
d[i] = d[i/3] + 1;
pre[i] = i/3;
}
}
cout << d[n] << '\n';
int cur = n;
while(true){
cout << cur << ' ';
if(cur == 1) break;
cur = pre[cur];
}
}