s.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 06 March 2019
  4. # https://github.com/trizen
  5. # Generalized algorithm for generating numbers that are smooth over a set A of primes, bellow a given limit.
  6. use 5.020;
  7. use warnings;
  8. use experimental qw(signatures);
  9. use Math::GMPz;
  10. use ntheory qw(:all);
  11. sub check_valuation ($n, $p) {
  12. ($n*$p)%2 == 0 or return 0;
  13. #~ if ($p > 13) {
  14. #~ return ( ($n % $p) != 0);
  15. #~ }
  16. 1;
  17. }
  18. sub smooth_numbers ($limit, $primes) {
  19. my @h = (1);
  20. foreach my $p (@$primes) {
  21. say "Prime: $p";
  22. foreach my $n (@h) {
  23. if ($n * $p <= $limit and check_valuation($n, $p)) {
  24. push @h, $n * $p;
  25. }
  26. }
  27. }
  28. return \@h;
  29. }
  30. #
  31. # Example for finding numbers `m` such that:
  32. # sigma(m) * phi(m) = n^k
  33. # for some `n` and `k`, with `n > 1` and `k > 1`.
  34. #
  35. # See also: https://oeis.org/A306724
  36. #
  37. my $t = 282669887501;
  38. my $base = 5;
  39. sub isok ($n) {
  40. #is_power(Math::GMPz->new(divisor_sum($n)) * euler_phi($n));
  41. my $k = $n+1;
  42. if ($k < $t) {
  43. return 0;
  44. }
  45. powmod($base, $k - 1, Math::GMPz->new($t) * $k) == 1;
  46. }
  47. my $h = smooth_numbers(2402694043751, primes(63));
  48. say "\nFound: ", scalar(@$h), " terms";
  49. my @list;
  50. foreach my $n (@$h) {
  51. my $p = isok($n);
  52. #if ($p >= 8) {
  53. if ($p) {
  54. say "Found: ", $n+1, " -> ", join(' * ', map { "$_->[0]^$_->[1]" } factor_exp($n)), ' -> ', is_prime($n+1) ? 'prime' : 'NOT PRIME';
  55. #push @{$table{$p}}, $n;
  56. #say "Found: ", $n+1;
  57. push @list, $n+1;
  58. }
  59. }
  60. say vecmin(@list);
  61. __END__
  62. a(29) = 282669887501