Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
最大公約数をユークリッドの互除法を使って再帰で実装する
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use DDP { deparse => 1 };
print "整数2つを入力して下さい i,j >>";
chomp(my $input = <STDIN>);
my ($i, $j) = split(/,/, $input);
say get_gcd($i, $j);
sub get_gcd{
my $x = shift;
my $y = shift;
my $mod = $x % $y;
my $result;
if ($mod == 0){
return $y;
} else {
return get_gcd($y, $mod);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.