結果

問題 No.443 GCD of Permutation
ユーザー yuruhiya
提出日時 2021-01-24 17:34:57
言語 Crystal
(1.14.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 332 bytes
コンパイル時間 11,846 ms
コンパイル使用メモリ 303,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 22:14:18
合計ジャッジ時間 12,361 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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
g = s.chars.map(&.to_i).uniq.combinations(2).map { |(i, j)|
  9 * (i - j).abs
}.reduce(0) { |acc, x| acc.gcd(x) }

if g == 0
  puts s
else
  puts s.to_big_i.gcd(g)
end
0