Skip to content

Commit cc6e114

Browse files
authored
Create 49_two_buttons_codeforces.cpp
1 parent 61d4248 commit cc6e114

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

49_two_buttons_codeforces.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -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+
else
30+
{
31+
m+=1; count++;
32+
}
33+
}
34+
cout<<count+(n-m)<<endl;
35+
}
36+
}

0 commit comments

Comments
 (0)