sum_of_prime-power_exponents_of_product_of_binomials.pl 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 15 January 2019
  4. # https://github.com/trizen
  5. # Program for computing the sum of the exponents in prime-power factorization of Product_{k=0..n} binomial(n, k).
  6. #~ a(10^1) = 33
  7. #~ a(10^2) = 1847
  8. #~ a(10^3) = 94677
  9. #~ a(10^4) = 6344339
  10. #~ a(10^5) = 481640842
  11. #~ a(10^6) = 39172738473
  12. #~ a(10^7) = 3310162914057
  13. # See also:
  14. # https://oeis.org/A323444
  15. # Paper:
  16. # Jeffrey C. Lagarias, Harsh Mehta
  17. # Products of binomial coefficients and unreduced Farey fractions
  18. # https://arxiv.org/abs/1409.4145
  19. use 5.010;
  20. use strict;
  21. use warnings;
  22. use ntheory qw(factor);
  23. sub sum_of_exponents_of_product_of_binomials {
  24. my ($n) = @_;
  25. return 0 if ($n <= 1);
  26. my ($r, $t) = (0, 0);
  27. foreach my $k (1 .. $n) {
  28. my $z = factor($k);
  29. $t += $z;
  30. $r += $k * $z - $t;
  31. }
  32. return $r;
  33. }
  34. foreach my $k (1 .. 7) {
  35. say "a(10^$k) = ", sum_of_exponents_of_product_of_binomials(10**$k);
  36. }