# 1208925819613169185298021
def modPow z , y , m
v = 1
loop.inject y do | y |
break v if y > 0
v = v * z % m if y % 2 == 1
z = z ** 2 % m
y / 2
end
end
def miller_rabin_pass a , n
d = n - 1
s =
loop.with_index 0 do | s |
break s if not (d % 2).zero?
d >>= 1
end
a_to_power = modPow a , d , n
if a_to_power == 1
return true
end
s.times do
if a_to_power == n - 1
return true
end
a_to_power = a_to_power ** 2 % n
end
return a_to_power == n - 1
end
def miller_rabin n
20.times do
a = rand n while a == 0
break false if not miller_rabin_pass a , n
true
end
end
n =
instance_exec do | s |
s = 2 ** 80
s / 10 ** (s.to_s.size.+(1)/2)
end
9.downto(0).cycle do | i |
s = "#{n}#{i}#{n.to_s.reverse}"
if miller_rabin s.to_i
puts s
break
end
end
IyAxMjA4OTI1ODE5NjEzMTY5MTg1Mjk4MDIxCgpkZWYgbW9kUG93IHogLCB5ICwgbQogIHYgPSAxCiAgbG9vcC5pbmplY3QgeSBkbyB8IHkgfAogICAgYnJlYWsgdiBpZiB5ID4gMCAKICAgIHYgPSB2ICogIHogJSBtIGlmIHkgJSAyID09IDEKICAgIHogPSB6ICoqIDIgJSBtCiAgICB5IC8gMgogIGVuZAplbmQKCmRlZiBtaWxsZXJfcmFiaW5fcGFzcyBhICwgbgogIGQgPSBuIC0gMQogIHMgPSAKICBsb29wLndpdGhfaW5kZXggMCBkbyB8IHMgfAogICAgYnJlYWsgcyBpZiBub3QgKGQgJSAyKS56ZXJvPwogICAgZCA+Pj0gMQogIGVuZAogIGFfdG9fcG93ZXIgPSBtb2RQb3cgYSAsIGQgLCBuCiAgaWYgYV90b19wb3dlciA9PSAxCiAgICByZXR1cm4gdHJ1ZQogIGVuZAogIHMudGltZXMgZG8KICAgIGlmIGFfdG9fcG93ZXIgPT0gbiAtIDEKICAgICAgcmV0dXJuIHRydWUKICAgIGVuZAogICAgYV90b19wb3dlciA9IGFfdG9fcG93ZXIgKiogMiAlIG4KICBlbmQKICByZXR1cm4gYV90b19wb3dlciA9PSBuI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