Skip to content

Instantly share code, notes, and snippets.

@ichirin2501
Created September 8, 2012 03:29
Show Gist options
  • Save ichirin2501/3671590 to your computer and use it in GitHub Desktop.
Save ichirin2501/3671590 to your computer and use it in GitHub Desktop.
Project Euler 48
#!/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