fork download
  1. from collections import defaultdict
  2. from time import clock
  3.  
  4. import primesieve
  5.  
  6. def count_last_digs():
  7. t0 = clock()
  8. counts = defaultdict(int)
  9. primes = primesieve.Iterator()
  10. primes.next_prime()
  11. primes.next_prime()
  12. primes.next_prime()
  13. p1 = primes.next_prime()
  14. p1d = p1 % 10
  15. limit = 10**6
  16. while True:
  17. p2 = primes.next_prime()
  18. p2d = p2 % 10
  19. counts[p1d, p2d] += 1
  20. if p2 > limit:
  21. print("{:_}".format(limit), clock() - t0)
  22. print_counts(counts)
  23. limit = 10*limit if limit <= 1000_000_000 else limit + 10_000_000_000
  24. p1d = p2d
  25. return counts
  26.  
  27. def print_counts(counts):
  28. S = sum(counts.values())
  29. C = {k: v / S for k, v in counts.items()}
  30. V = [1, 3, 7, 9]
  31. for v1 in V:
  32. for v2 in V:
  33. print("{:6.3f}".format(C[v1, v2]), end=" ")
  34. print()
  35. print()
  36.  
  37. count_last_digs()
  38.  
  39.  
  40. """
  41. 1_000_000
  42. 0.041 0.080 0.083 0.045
  43. 0.056 0.036 0.074 0.085
  44. 0.065 0.069 0.037 0.079
  45. 0.089 0.065 0.056 0.040
  46.  
  47. 10_000_000
  48. 0.043 0.078 0.080 0.049
  49. 0.058 0.039 0.073 0.080
  50. 0.064 0.069 0.039 0.078
  51. 0.085 0.065 0.058 0.042
  52.  
  53. 100_000_000
  54. 0.044 0.076 0.078 0.052
  55. 0.059 0.042 0.072 0.078
  56. 0.064 0.068 0.042 0.076
  57. 0.083 0.064 0.059 0.044
  58.  
  59. 1_000_000_000
  60. 0.046 0.075 0.076 0.054
  61. 0.060 0.044 0.071 0.076
  62. 0.064 0.068 0.044 0.075
  63. 0.080 0.064 0.060 0.046
  64.  
  65. 10_000_000_000
  66. 0.047 0.074 0.074 0.055
  67. 0.060 0.046 0.070 0.074
  68. 0.064 0.067 0.046 0.074
  69. 0.079 0.064 0.060 0.047
  70.  
  71.  
  72. 340_000_000_000 14630.772475548303
  73. 0.049 0.072 0.072 0.057
  74. 0.061 0.048 0.069 0.072
  75. 0.063 0.067 0.048 0.072
  76. 0.077 0.063 0.061 0.049
  77.  
  78. 350_000_000_000 15045.708864189168
  79. 0.049 0.072 0.072 0.057
  80. 0.061 0.048 0.069 0.072
  81. 0.063 0.067 0.048 0.072
  82. 0.077 0.063 0.061 0.049
  83.  
  84. 1_140_000_000_000 32903.831111384796
  85. 0.049 0.072 0.072 0.057
  86. 0.061 0.048 0.069 0.072
  87. 0.063 0.066 0.048 0.072
  88. 0.076 0.063 0.061 0.049
  89.  
  90. 2_610_000_000_000 73682.21293810359
  91. 0.049 0.072 0.072 0.057
  92. 0.061 0.049 0.069 0.072
  93. 0.063 0.066 0.049 0.072
  94. 0.076 0.063 0.061 0.049
  95.  
  96. 3_130_000_000_000 88038.33787216355
  97. 0.050 0.072 0.071 0.057
  98. 0.061 0.049 0.069 0.071
  99. 0.063 0.066 0.049 0.072
  100. 0.076 0.063 0.061 0.050
  101.  
  102. 4_240_000_000_000 118131.35975553434
  103. 0.050 0.072 0.071 0.057
  104. 0.061 0.049 0.068 0.071
  105. 0.063 0.066 0.049 0.072
  106. 0.076 0.063 0.061 0.050
  107.  
  108. """
Runtime error #stdin #stdout #stderr 0.03s 27704KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
  File "./prog.py", line 23
    limit = 10*limit if limit <= 1000_000_000 else limit + 10_000_000_000
                                            ^
SyntaxError: invalid syntax