結果

問題 No.2558 中国剰余定理
ユーザー chaemonchaemon
提出日時 2023-12-02 14:32:15
言語 Nim
(2.0.2)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 14,867 bytes
コンパイル時間 4,401 ms
コンパイル使用メモリ 93,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-26 16:45:50
合計ジャッジ時間 5,746 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 25 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 95 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 22 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 25 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 29 ms
5,376 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 29 ms
5,376 KB
testcase_25 AC 29 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 18 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 9 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import macros
macro Please(x): untyped = nnkStmtList.newTree()

Please use Nim-ACL
Please use Nim-ACL
Please use Nim-ACL


static:
  when not defined SecondCompile:
    # md5sum: 004fb116feb693202d320b197beb6a4d  atcoder.tar.xz

    template getFileName():string = instantiationInfo().filename
    let fn = getFileName()
    block:
      let (output, ex) = gorgeEx("if [ -e ./atcoder ]; then exit 1; else exit 0; fi")
      # doAssert ex == 0, "atcoder directory already exisits"
    discard staticExec("echo \"/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4O//J3tdADCdCIqmAHyeLmzPetXzWpgQcDgKgJF+nO8CaeoEXtPO/uIeToqY0AR+IS4C3rNgspWiUSryfblqVx3nHHh5zssJfnU8Oak3mCtyYYyORqw0t1dvPpzz67EIaqnGKhtI7ercqQjqIfRWzqYOuoylhHVIpXNO5K1XxXMrxO3sY1o+R8EioVLg+VBFwu36Db3HNuGVKKiszoNxcdQ+tziih4rtZEpS4n9NB+W+e97YlO2J07q8jcC+mfg7ljh2mD+lrg+YBfiRJhffE/b5SBo6whLf1bAdC49ItSjpkbm/BH74+f4Gd1Ke5tAUSZYtTRl23KQ62mVTqfUIVm0uguLi6eoJuwdByr6RE28yR6kvDRkhNlTQ0nhYrLjfKz4JelYToKhCkYsFfJ6oPMj91+rxMMiML+VH3xKhY23gbtrzQ8aSAZzQmbQgx9C3VWtpzlPyzJg3Iy3m4+EQQQ5PbdQaa70FieY0BZTU0SSpdsZiik9wplNuhCQ5dc48ovnFTOFM6tEEmwPMYpoA9HYu6LYg9vPLGW+OhA2wifzPfe2PPUPeHgGJHbaMEArwGESexyi4GSkUaDXKXzQZHd5OXvSeATt3znbqxVgE32k5Yb0VJbUZsWt4VSg9ehl7cgYlSBcnMBUG3CFHy5A7jkZtYvJyzsJnVmlzKk7SgjnsKxIfg1bhqS1LLLDCLnXRxzXWz2p4jIkfbDxMW9lQoEJ213GR2BH2EcsKIJpDCOdNwjiVlW5E1EfuHQ9tHGaFMJYnRvgBgcAw7QbfM+BaBqS1AAQiFPdC4KmJ0a5GVLdGivGpn8fLdr4y5XMU4TMoG5DJokZyia7cFoDZu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WsfXefQJNqzP0Fr92UVKAvhhMTqz0QdmbSSWfzJf2oIu1WsgpGVn6aeV9VZkTtU8kONoHaQUt7AzVo4AKvxrv7ZepC5q4bubnp7yfhw669yRNTfHKgXNJW5fue3vGiBvgoi2MygJMeFZgGvmRqBYSOvowrCAk6O4VR7FHVaxxpdAUH+rQW5WTjv0tqokBEi4OFB1H537wxK5DsxRcnxQZKtmZoyaULTCKMTZk0fLl0ecG1vbeaiNGMrXcv0T2O+hKHWyPGa2eNixNQvQEztw+QWOWzAwaXINjeub9xIGgEsqsTWtlLB5WbxWlfMrwnKkVv/GhVufpYa9dwDND9sy0z6ibe6UVscKhG2pONOi910UWQ37VB3/tL8l6fhhBIUYDrJwFK6l5fAsrSir0hg/f6RxkA7jLdVgPPjBLqSTAuYHQpoPlDPolDkb70h5Huy/RGukjg6zq5GbkurrDP3SOb4Ka4SgLoiqqHgczIupzvVSnpS0GzuEfg0FEqUhUWthZVMLjGe6bnMugNgMyYADYRRToUqokK3Ut4LfWkMc44vyz0eUDP+yrELW5E28TkdYjXPVWmWvGKo6+jVQ12I8qd1273bXjr9rJJ6O/NXVhc/IyGP7Fjq7jQQeyhVmiYA3/J4xRx9JRmKjz1L+ThGVoMv95Y9CKLj8LrLrgG7mJeQ/kwy/MPuKVcxK3eDLsEIs4oYvpDB/ltoDmoumn9elnb2ScOllHwHGxmmcCBRsDZPHVAAAAwF0P9KFFlQ4AAZdPgOADAOYIA3axxGf7AgAAAAAEWVo=\" | base64 -d > atcoder.tar.xz && tar -Jxvf atcoder.tar.xz")
    let (output, ex) = gorgeEx("nim cpp -d:release -d:SecondCompile -d:danger --path:./ --opt:speed --multimethods:on --warning[SmallLshouldNotBeUsed]:off --checks:off -o:a.out " & fn)
    discard staticExec("rm -rf ./atcoder");doAssert ex == 0, output;quit(0)


when defined SecondCompile:
  const DO_CHECK = false;const DEBUG = false
else:
  const DO_CHECK = true;const DEBUG = true
const
  USE_DEFAULT_TABLE = true
  DO_TEST = false

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/header/chaemon_header.nim
include atcoder/extra/header/chaemon_header


proc solve() =
  let A, B, a, b = nextInt()
  var x = 0
  while true:
    if x mod A == a and x mod B == b:
      echo x;return
    x.inc

solve()

0