結果

問題 No.816 Beautiful tuples
ユーザー かりあげクンかりあげクン
提出日時 2020-08-24 11:35:56
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 486 bytes
コンパイル時間 3,467 ms
コンパイル使用メモリ 65,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 03:04:13
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
import strutils
import algorithm

proc divisor(n : int) : seq[int] =
  result = newSeq[int](0)
  var n = n
  var i = 1
  while i * i <= n:
    if n mod i == 0:
      result.add(i)
      if i * i != n: result.add(n div i)
    i += 1
  result.sort()

var ab = stdin.readLine.split.map(parseInt)
var (a, b) = (ab[0], ab[1])
var n = a + b
var ans = -1
for c in divisor(n):
  if c != a and c != b:
    if ((c + a) mod b == 0 ) and ((c + b) mod a == 0):
      ans = c
echo ans
0