/* file : pathLeastResistance.c */ /* author : Oscar MirĂ³ (o.miro.i.lopez.feliu@student.rug.nl) */ /* Description: * */ #include #include int check (int start, int dest, int count, int lim) { if (lim%2 == 0) lim /= 2; if (start == dest || count == lim) { return count; } else { int method[5]; method[0] = check(start+1, dest, count+1, lim); method[1] = check(start-1, dest, count+1, lim); method[2] = check(start*5, dest, count+1, lim); if (start % 2 == 0) { method[3] = check(start/2, dest, count+1, lim); } else { method[3] = lim; } if (start % 3 == 0) { method[4] = check(start/3, dest, count+1, lim); } else { method[4] = lim; } int min = lim; for (int i = 0; i < 5; i++) { if (min > method[i]) { min = method[i]; } } return min; } } int main (int argc, char *argv[]) { int start, dest; scanf("%d %d", &start, &dest); printf("%d\n", check(start, dest, 0, abs(dest-start))); }