Last active
December 11, 2015 09:39
-
-
Save tokubass/4581631 to your computer and use it in GitHub Desktop.
use bigintのテスト。Math::BigIntに変換してくれている。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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