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