結果

問題 No.443 GCD of Permutation
ユーザー yuruhiya
提出日時 2021-01-24 17:22:47
言語 Crystal
(1.14.0)
結果
TLE  
実行時間 -
コード長 362 bytes
コンパイル時間 10,973 ms
コンパイル使用メモリ 299,076 KB
実行使用メモリ 490,756 KB
最終ジャッジ日時 2024-06-30 22:13:24
合計ジャッジ時間 13,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

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
n = s.size
if s.count(s[0]) == n
  puts s
  exit
end

p (0...n).to_a.combinations(2).map { |(i, j)|
  ("#{s[i]}#{s[j]}".to_i - "#{s[j]}#{s[i]}".to_i).abs
}.reduce(0) { |i, j| i.gcd(j) }.gcd(s.to_i)
0