iterative_upper-bounds.pl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 08 July 2019
  4. # https://github.com/trizen
  5. use 5.020;
  6. use Math::GMPz;
  7. use ntheory qw(:all);
  8. use experimental qw(signatures);
  9. my @primes = (@{primes(1000)});
  10. my %table;
  11. sub f($n) {
  12. my $count = -1;
  13. while (is_semiprime($n) && !is_square($n)) {
  14. my ($x, $y) = factor($n);
  15. $n = ($y - $x);
  16. ++$count;
  17. }
  18. $count;
  19. }
  20. my $from = Math::GMPz->new("5");
  21. my @arr = [f($from), $from];
  22. foreach my $n (@arr) {
  23. foreach my $p (@primes) {
  24. my $t = $p * ($n->[1] + $p);
  25. if (is_semiprime($t) and !is_square($t)) {
  26. my $count = $n->[0] + 1;
  27. push @arr, [$count, $t];
  28. #if ($count == 3) {
  29. # say join ', ', map{$_->[1]}grep{$_->[0] == 1}@arr;
  30. #say "$t = $p * ($n->[1] + $p)";
  31. #}
  32. if (exists $table{$count}) {
  33. if ($t < $table{$count}) {
  34. $table{$count} = $t;
  35. say "a($count) <= $t";
  36. }
  37. }
  38. else {
  39. $table{$count} = $t;
  40. say "a($count) <= $t";
  41. }
  42. }
  43. }
  44. }