fork download
  1. use List::Util qw(sum);
  2. use bigint;
  3.  
  4. my @memo = (0 => 1);
  5.  
  6. sub fact {
  7. my ($n) = @_;
  8. return $memo[$n] //= $n * fact($n - 1);
  9. }
  10.  
  11. sub is_prime {
  12. my ($n) = @_;
  13. return (fact($n - 1) + 1) % $n == 0;
  14. }
  15.  
  16. print sum grep{ not is_prime $_ } (1..10000);
Time limit exceeded #stdin #stdout 5s 160448KB
stdin
Standard input is empty
stdout
Standard output is empty