#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my ($x, $y) = split / /, <>; chomp $y; if ($x == $y) { print 0; exit; } my @q; push @q, [$y, $x, 1]; push @q, [$x + $y, $x - $y, 1]; my %vis; while (scalar @q) { my ($x, $y, $c) = @{shift @q}; if ($x == $y) { print $c; exit; } my @mark = ($x, $y); if (!exists $vis{@mark}) { $vis{@mark} = 1; push @q, [$y, $x, $c + 1]; push @q, [$x + $y, $x - $y, $c + 1]; } } print -1