smooth_generator.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/perl
  2. # Positions of records in A306440.
  3. # https://oeis.org/A307221
  4. # Where A306440(n) is defined as:
  5. # Number of different ways of expressing 2*n as (p - 1)*(q - 1), where p < q are primes
  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. if ($p == 2) {
  13. return valuation($n, $p) < 5;
  14. }
  15. if ($p == 3) {
  16. return valuation($n, $p) < 3;
  17. }
  18. if ($p == 7) {
  19. return valuation($n, $p) < 3;
  20. }
  21. ($n % $p) != 0;
  22. }
  23. sub smooth_numbers ($limit, $primes) {
  24. my @h = (1);
  25. foreach my $p (@$primes) {
  26. say "Prime: $p";
  27. foreach my $n (@h) {
  28. if ($n * $p <= $limit) { #and check_valuation($n, $p)) {
  29. push @h, $n * $p;
  30. }
  31. }
  32. }
  33. return \@h;
  34. }
  35. sub decompositions {
  36. my ($n) = @_;
  37. #say "N -> $n";
  38. my $count = 0;
  39. #my $max = sqrtint($n);
  40. foreach my $d(divisors($n)) {
  41. #last if ($d >= $max);
  42. $d < $n/$d or last;
  43. if (is_prime($d+1) and is_prime(($n/$d)+1)) {
  44. #say "$d, ", $n/$d, ' -> ', $d * ($n/$d);
  45. ++$count;
  46. }
  47. }
  48. $count;
  49. }
  50. my $h = smooth_numbers(275675400, primes(43));
  51. say "\nFound: ", scalar(@$h), " terms";
  52. my %table;
  53. foreach my $n (@$h) {
  54. $n > 151351200 or next;
  55. my $p = decompositions(2*$n);
  56. # $p > 32 or next;
  57. if (not exists $table{$p}) {
  58. $table{$p} = $n;
  59. }
  60. else {
  61. if ($table{$p} > $n) {
  62. $table{$p} = $n;
  63. }
  64. }
  65. #if ($p >= 8) {
  66. # say "a($p) = $n -> ", join(' * ', map { "$_->[0]^$_->[1]" } factor_exp($n));
  67. # # push @{$table{$p}}, $n;
  68. # }
  69. }
  70. use Data::Dump qw(pp);
  71. pp \%table;