fork download
  1. # 1208925819613169185298021
  2.  
  3. def modPow z , y , m
  4. v = 1
  5. loop.inject y do | y |
  6. break v if y > 0
  7. v = v * z % m if y % 2 == 1
  8. z = z ** 2 % m
  9. y / 2
  10. end
  11. end
  12.  
  13. def miller_rabin_pass a , n
  14. d = n - 1
  15. s =
  16. loop.with_index 0 do | s |
  17. break s if not (d % 2).zero?
  18. d >>= 1
  19. end
  20. a_to_power = modPow a , d , n
  21. if a_to_power == 1
  22. return true
  23. end
  24. s.times do
  25. if a_to_power == n - 1
  26. return true
  27. end
  28. a_to_power = a_to_power ** 2 % n
  29. end
  30. return a_to_power == n - 1
  31. end
  32.  
  33.  
  34. def miller_rabin n
  35. 20.times do
  36. a = rand n while a == 0
  37. break false if not miller_rabin_pass a , n
  38. true
  39. end
  40. end
  41.  
  42. n =
  43. instance_exec do | s |
  44. s = 2 ** 80
  45. s / 10 ** (s.to_s.size.+(1)/2)
  46. end
  47.  
  48. 9.downto(0).cycle do | i |
  49. s = "#{n}#{i}#{n.to_s.reverse}"
  50. if miller_rabin s.to_i
  51. puts s
  52. break
  53. end
  54. end
  55.  
  56.  
Success #stdin #stdout 0.02s 7464KB
stdin
Standard input is empty
stdout
1208925819619169185298021