prog.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/perl
  2. # Smallest m such that each digit (0-9) appears exactly n times in the concatenation of m and pi(m).
  3. # https://oeis.org/A323604
  4. # 102756, 10013236879, 1000112354597667
  5. use 5.014;
  6. use strict;
  7. use warnings;
  8. use Math::GMPz;
  9. use ntheory qw(:all);
  10. # 100000000000000000000
  11. # 100001112222333344445
  12. my $from = Math::GMPz->new(10)**20;
  13. my $count = Math::GMPz->new("2220819602560918840");
  14. for (;;) {
  15. say "Testing $from";
  16. my %hash;
  17. $hash{$_}++ for split(//, "$from$count");
  18. if (vecall {$_ == 2} values %hash) {
  19. die "\nFound term: $from (primepi = $count)\n";
  20. }
  21. $from = next_prime($from);
  22. Math::GMPz::Rmpz_add_ui($count, $count, 1);
  23. }
  24. __END__
  25. PRIME PI < 10^n
  26. 0 0
  27. 1 4
  28. 2 25
  29. 3 168
  30. 4 1229
  31. 5 9592
  32. 6 78498
  33. 7 664579
  34. 8 5761455
  35. 9 50847534
  36. 10 455052511
  37. 11 4118054813
  38. 12 37607912018
  39. 13 346065536839
  40. 14 3204941750802
  41. 15 29844570422669
  42. 16 279238341033925
  43. 17 2623557157654233
  44. 18 24739954287740860
  45. 19 234057667276344607
  46. 20 2220819602560918840
  47. 21 21127269486018731928
  48. 22 201467286689315906290
  49. 23 1925320391606803968923
  50. 24 18435599767349200867866
  51. 25 176846309399143769411680
  52. 26 1699246750872437141327603
  53. 27 16352460426841680446427399