結果

問題 No.443 GCD of Permutation
ユーザー d9et
提出日時 2020-04-17 23:30:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 565 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 61,900 KB
最終ジャッジ日時 2024-10-03 15:33:04
合計ジャッジ時間 2,588 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import Counter
def gcds(ls):
  ret = 0
  for i in ls:
    if ret*i == 0:
      ret = max(ret,i)
    else:
      ret = gcd(ret,i)
  return ret
n = input()
c = Counter(n)
d = list(int(i) for i in c.keys())
ans = 1
if len(d) == 1:
  ans = n
else:
  if len(d) == 2 and 0 in d:
    ans *= max(d)
  elif gcds(d) != 1:
    b = gcds(d)
    if b%3:
      ans *= b
    else:
      ans *= b//3
    dsum = 0
    for i,j in c.items():
      dsum += int(i)*j
    if dsum%9 == 0:
      ans *= 9
    elif dsum%3 == 0:
      ans *= 3
print(ans)
0