e_primorial.pl 949 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 04 September 2015
  5. # Website: https://github.com/trizen
  6. # Compute a new constant, called e-primorial
  7. # using the following formula:
  8. # 1 + sum({n=0, Inf}, 1/n#)
  9. # where 'n#' is the product of the first n primes.
  10. # Example:
  11. # 1 + 1/2 + 1/(2*3) + 1/(2*3*5) + 1/(2*3*5*7)
  12. use 5.010;
  13. use strict;
  14. use warnings;
  15. use bignum (try => 'GMP');
  16. use ntheory qw(forprimes);
  17. my $s = 0;
  18. my $p = 1;
  19. forprimes {
  20. $s += 1 / ($p *= $_);
  21. }
  22. 1000;
  23. say $s;
  24. __END__
  25. 0.705230171791800965147431682888248513743607733565505914344254271579448720350814858381153069719904774040199744849124258793026220304812181974452618661012021323159778159738892351792865007915208229244324416883081570696757761526547730409991939570626315095656064297092991040559037018681680261221057850602197069242610518384960529122692938064843534568180026418571495177395781060935455813529379203383024423075030933708131887415