Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long bfs(long long n, long long m) {
- map<long long, long long> count;
- long long aux, value;
- queue<long long> fila;
- fila.push(n);
- count[n] = 0;
- while(!fila.empty()) {
- value = fila.front();
- fila.pop();
- cout<<value<<endl;
- if (value == m) return count[value];
- aux = value * 2;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1;
- }
- if (aux == m) return count[aux];
- aux = value * 3;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1;
- }
- if (aux == m) return count[aux];
- aux = value / 2;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1;
- }
- if (aux == m) return count[aux];
- aux = value / 3;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1;
- }
- if (aux == m) return count[aux];
- aux = value + 7;
- cout<<count[value]<<endl;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1, count[aux];
- }
- if (aux == m) return count[aux];
- aux = value - 7;
- if (count[aux] == 0) {
- fila.push(aux);
- count[aux] = count[value] + 1;
- }
- if (aux == m) return count[aux];
- }
- return 0;
- }
- int main() {
- long long n, m;
- scanf("%lld %lld", &n, &m);
- printf("%lld\n", (bfs(n, m)));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement