# a, b が与えられたとき ax + by = gcd(a, b) となる x, y を返す
def euclid(a, b)
return [0, 1] if a == 0
x, y = euclid(b % a, a)
[y - b / a * x, x]
end
N = 123456789
M = 10 ** 9
max = 0
(M - 1).step(1, -2) do |x|
next if x % 5 == 0
break if x * (M - 1) <= max
y = euclid(x, M).first * N % M * x
max = y if y > max
end
p max
IyBhLCBiIOOBjOS4juOBiOOCieOCjOOBn+OBqOOBjSBheCArIGJ5ID0gZ2NkKGEsIGIpIOOBqOOBquOCiyB4LCB5IOOCkui/lOOBmQpkZWYgZXVjbGlkKGEsIGIpCiAgcmV0dXJuIFswLCAxXSBpZiBhID09IDAKICB4LCB5ID0gZXVjbGlkKGIgJSBhLCBhKQogIFt5IC0gYiAvIGEgKiB4LCB4XQplbmQKCk4gPSAxMjM0NTY3ODkKTSA9IDEwICoqIDkKCm1heCA9IDAKKE0gLSAxKS5zdGVwKDEsIC0yKSBkbyB8eHwKCW5leHQgaWYgeCAlIDUgPT0gMAoJYnJlYWsgaWYgeCAqIChNIC0gMSkgPD0gbWF4Cgl5ID0gZXVjbGlkKHgsIE0pLmZpcnN0ICogTiAlIE0gKiB4CgltYXggPSB5IGlmIHkgPiBtYXgKZW5kCgpwIG1heA==