-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy path1 to x.cpp
More file actions
44 lines (41 loc) · 772 Bytes
/
1 to x.cpp
File metadata and controls
44 lines (41 loc) · 772 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
#include<iostream>
using namespace std;
int min(int a, int b){
if(a <= b && a != 0)
return a;
else if(b != 0)
return b;
}
int value(int x, int* p){
int s1 = 0, s2 = 0, s3 = 0, steps;
if(x == 1){
p[0] = x;
return 0;
}
if(x%3 != 0){
s1 = value(x-1,p+1);
p[0] = x;
s1++;
}
if(x%2 == 0){
s2 = value(x/2,p+1);
p[0] = x;
s2++;
}
if(x%3 == 0){
s3 = value(x/3,p+1);
p[0] = x;
s3++;
}
steps = min(min(s3,s2),s1);
//for(int i = 0; i < steps; i++)
// cout << p[i] << " ";
return steps;
}
int main(){
int x;
cin >> x;
int p[100];
cout << value(x,p);
return 0;
}