Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a solution for Euler #288.
It's very slow , but is working fine.
  • Loading branch information
shlomif committed Jul 29, 2015
1 parent 14f4dd9 commit 824562a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions categories/euler/prob288-shlomif.p6
@@ -0,0 +1,47 @@
use v6;

sub factorial_factor_exp($n , $f)
{
if ($n < $f)
{
return 0;
}
else
{
my $div = $n / $f;
return $div + factorial_factor_exp($div, $f);
}
}

my @t_n;

my $N_LIM = 10;
my $BASE = 61;
my $LIM = 10_000_000;

my $S_0 = 290797;
my $s = $S_0;

for (0 .. $N_LIM-1) -> $n {
@t_n.push($s % $BASE);
$s = (($s * $s) % 50515093);
}

my $sum = 0;
for ($N_LIM .. $LIM) -> $n {
if $n % 10_000 == 0 {
say "Reached $n";
}
$sum += ($s % $BASE);
$s = (($s * $s) % 50515093);
}

sub f($n)
{
return factorial_factor_exp($n, ($BASE)) % (($BASE) ** $N_LIM);
}

say "Solution == ", +([+] (
(map { f(($BASE) ** $_) * @t_n[$_] }, 1 .. @t_n-1),
$sum * f(($BASE) ** $N_LIM)
)) % (($BASE) ** $N_LIM);

0 comments on commit 824562a

Please sign in to comment.