#define _CRT_SECURE_NO_WARNINGS
#include <iostream> // cpp
using namespace std;
int a, b;
void INPUT()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> a >> b;
}
void SOLVE()
{
// Requirement : Output (min value + 1)
int ans = 1;
/* I used Greedy Algorithm.Tried to change B to A.
* Why B to A?
* => It can be hard to find what calc is useful to make A to B.
*/
while (a != b)
{
// B should not smaller than A
// B should do calculate % 10 or % 2
if(b < a || (b % 10 != 1 && b % 2 == 1))
{
ans = -1;
break;
}
// Only Two Possiblity
if (b % 10 == 1) b /= 10;
else if (b % 2 == 0) b /= 2;
ans++;
}
cout << ans;
}
/* You can also use BFS to solve this problem. */
int main()
{
INPUT();
SOLVE();
}
GOLD5 미만 난이도는 알고리즘 및 풀이 설명을 주석으로 대체합니다.
주석을 참고해주세요.