prog.pl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl
  2. # Number of positive integers with n digits that are the product of two integers ending with 3.
  3. # https://oeis.org/A346952
  4. # Known terms:
  5. # 1, 3, 37, 398, 4303, 45765, 480740, 5005328, 51770770, 532790460
  6. use 5.020;
  7. use ntheory qw(:all);
  8. use experimental qw(signatures);
  9. sub a ($n) {
  10. my $lim = powint(10, $n-1);
  11. my $count = 0;
  12. my %seen;
  13. foreach my $u (1 .. divint($lim, 10*3)) {
  14. my $k = $u . '3';
  15. foreach my $m (divint($lim, 10*$k)..divint($lim, $k)) {
  16. my $r = mulint($k , $m . '3');
  17. if (length($r) > $n) {
  18. #~ say "Above limit for $k -- $m -- gives $r";
  19. last;
  20. }
  21. if (length($r) == $n) {
  22. ++$count if !$seen{$r}++;
  23. }
  24. }
  25. }
  26. foreach my $k (3) {
  27. foreach my $m (divint($lim, 10*$k)..divint($lim, $k)) {
  28. my $r = mulint($k , $m . '3');
  29. #~ if (length($r) > $n) {
  30. #~ say "Above limit $k -- $m -- gives $r";
  31. #~ last;
  32. #~ }
  33. if (length($r) == $n) {
  34. ++$count if !$seen{$r}++;
  35. }
  36. }
  37. }
  38. return $count;
  39. }
  40. local $| = 1;
  41. foreach my $n (1..100) {
  42. print(a($n), ", ");
  43. }