Skip to content

Instantly share code, notes, and snippets.

@tokubass
Last active December 11, 2015 09:39
Show Gist options
  • Save tokubass/4581631 to your computer and use it in GitHub Desktop.
Save tokubass/4581631 to your computer and use it in GitHub Desktop.
use bigintのテスト。Math::BigIntに変換してくれている。
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use bigint lib => 'GMP';
use Test::More;
subtest 'Project Euler - Problem 3' => sub {
my $n = 6008514751430000000000000000000000000000000000000000000000000000;
my $proof_expected = $n;
my @list;
my $max_loop = int(sqrt($n));
for ( my $i = 2; $i < $max_loop; $i++ ) {
while ( $n % $i == 0 ) {
$n /= $i;
push @list, $i;
}
last if $n == 1;
}
say "$n: @list";
my $proof = 1;
$proof *= $_ for @list;
is($proof, $proof_expected);
};
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment