my ($n, $p) = get.words; put $n; put $p; put solve($n.Int, $p.Rat); sub solve(Int $n, Rat $p) { my $p2 = 1.0 - $p; my @s = gather for 1..$n+1 { take 1.0 }; my $ans = 0.0; for 2..$n -> $i { $ans = $ans + @s[$i]; for $i*2,$i*3...$n -> $j { @s[$j] = @s[$j] * $p2; } } return $ans; }