Created
September 8, 2012 03:29
-
-
Save ichirin2501/3671590 to your computer and use it in GitHub Desktop.
Project Euler 48
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/perl | |
use warnings; | |
use strict; | |
use bigint; | |
use List::Util qw/sum/; | |
my $mod = 10**10; | |
sub binmod{ | |
my ($x, $y) = @_; | |
return 1 if $y == 0; | |
my $z = &binmod($x, $y/2); | |
if( $y % 2 == 0 ){ | |
return ($z * $z) % $mod; | |
} | |
else{ | |
return ($z * $z * $x) % $mod; | |
} | |
} | |
print sum(map{ &binmod($_,$_) } 1..1000) % $mod,"\n"; | |
# 9110846700 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment