We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 61d4248 commit cc6e114Copy full SHA for cc6e114
49_two_buttons_codeforces.cpp
@@ -0,0 +1,36 @@
1
+//
2
+// main.cpp
3
+// Two Buttons
4
+
5
6
+// Created by Prince Kumar on 13/08/19.
7
+// Copyright © 2019 Prince Kumar. All rights reserved.
8
9
10
+/// TWO BUTTONS --> Code-forces
11
12
+#include <iostream>
13
+using namespace std;
14
+int main()
15
+{
16
+ int n,m; cin>>n>>m;
17
+ if(n>=m)
18
+ { // 10 1
19
+ cout<<n-m<<endl;
20
+ }
21
+ else
22
+ {
23
+ // back tracking
24
+ int count=0;
25
+ while(m>n)
26
27
+ if(m%2==0)
28
+ {m/=2; count++;}
29
30
31
+ m+=1; count++;
32
33
34
+ cout<<count+(n-m)<<endl;
35
36
+}
0 commit comments