// yukicoder: No.643 Two Operations No.2 // 2019.7.13 bal4u #include #define SFT 500 #define MAX 1000 #define ABS(x) ((x)>=0?(x):-(x)) typedef struct { int x, y, s; } Q; Q q[100000]; int top, end; char vis[MAX+2][MAX+2]; int main() { int x, y, s, ans = -1; scanf("%d%d", &x, &y); q[0].x = x, q[0].y = y, end = 1; while (top != end) { x = q[top].x, y = q[top].y, s = q[top++].s; if (x == y) { ans = s; break; } if (vis[SFT+x][SFT+y]) continue; vis[SFT+x][SFT+y] = 1; q[end].x = y, q[end].y = x, q[end++].s = s+1; if (ABS(x+y) <= SFT && ABS(x-y) <= SFT) q[end].x = x+y, q[end].y = x-y, q[end++].s = s+1; } printf("%d\n", ans); return 0; }