結果

問題 No.186 中華風 (Easy)
ユーザー 👑 obakyanobakyan
提出日時 2022-04-03 18:26:55
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 7,032 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-15 16:07:18
合計ジャッジ時間 1,457 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 13 ms
4,376 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 14 ms
4,380 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 4 ms
4,504 KB
testcase_19 AC 26 ms
4,376 KB
testcase_20 AC 26 ms
4,376 KB
testcase_21 AC 26 ms
4,376 KB
testcase_22 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local function getgcd(x, y)
  while 0LL < x do
    x, y = y % x, x
  end
  return y
end

local function getlcm(x, y)
  local gcd = getgcd(x, y)
  return (x / gcd) * y
end

local x1, y1 = io.read("*n", "*n")
local x2, y2 = io.read("*n", "*n")
local x3, y3 = io.read("*n", "*n")
local v = x1 * 1LL
y1 = y1 * 1LL
if v == 0LL then v = y1 end
x2 = x2 * 1LL
y2 = y2 * 1LL
x3 = x3 * 1LL
y3 = y3 * 1LL
local f = false
for irep = 1, 2000000 do
  if v % y2 == x2 then f = true break end
  v = v + y1
end
if not f then print(-1) os.exit() end
local lcm = getlcm(y1, y2)
f = false
for irep = 1, 2000000 do
  if v % y3 == x3 then f = true break end
  v = v + lcm
  if v < 0LL then break end
end
if not f then print(-1) os.exit() end
v = tostring(v):gsub("LL", "")
print(v)
0