結果

問題 No.443 GCD of Permutation
ユーザー yuruhiyayuruhiya
提出日時 2021-01-24 17:29:59
言語 Crystal
(1.11.2)
結果
AC  
実行時間 302 ms / 1,000 ms
コード長 361 bytes
コンパイル時間 18,588 ms
コンパイル使用メモリ 263,776 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-09-13 13:21:48
合計ジャッジ時間 21,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,724 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,612 KB
testcase_03 AC 3 ms
4,728 KB
testcase_04 AC 2 ms
4,692 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,688 KB
testcase_07 AC 2 ms
4,596 KB
testcase_08 AC 3 ms
4,668 KB
testcase_09 AC 3 ms
4,600 KB
testcase_10 AC 3 ms
4,668 KB
testcase_11 AC 3 ms
4,600 KB
testcase_12 AC 2 ms
4,664 KB
testcase_13 AC 2 ms
4,728 KB
testcase_14 AC 78 ms
4,604 KB
testcase_15 AC 35 ms
4,832 KB
testcase_16 AC 6 ms
4,728 KB
testcase_17 AC 10 ms
4,760 KB
testcase_18 AC 186 ms
5,020 KB
testcase_19 AC 13 ms
4,680 KB
testcase_20 AC 213 ms
4,932 KB
testcase_21 AC 33 ms
4,760 KB
testcase_22 AC 3 ms
4,752 KB
testcase_23 AC 2 ms
4,612 KB
testcase_24 AC 3 ms
4,688 KB
testcase_25 AC 71 ms
4,980 KB
testcase_26 AC 64 ms
4,928 KB
testcase_27 AC 39 ms
4,860 KB
testcase_28 AC 79 ms
4,952 KB
testcase_29 AC 78 ms
4,912 KB
testcase_30 AC 78 ms
4,900 KB
testcase_31 AC 302 ms
5,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

require "big"

s = read_line
a = s.chars.map(&.to_i).sort
n = a.size

g = 0
(0...n).each { |i|
  (i + 1...n).each { |j|
    g = g.gcd(9*(a[j] - a[i])) if a[j] != a[i]
  }
}
if g == 0
  puts s
else
  puts s.to_big_i.gcd(g)
end
0