結果

問題 No.443 GCD of Permutation
ユーザー mban
提出日時 2017-07-26 07:19:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 811 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2024-10-09 17:33:21
合計ジャッジ時間 2,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1 RE * 1
other AC * 6 WA * 6 RE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def GCD(a, b):
    if a < b:
        t = a
        a = b
        b = t
    if b == 0:
        return a
    r = a % b
    while r > 0:
        a = b
        b = r
        r = a % b
    return b

N = input()

Use = [False for i in range(10)]

for c in N:
    Use[int(c)] = True

if Use.count(True) == 1:
    print(N)
else:
    g = 0

    for i in range(9):
        if not Use[i]:
            continue
        for j in range(i + 1, 10):
            if not Use[j]:
                continue
            g = GCD(g, 9 * (j - i))

    IntegerN = int(N)

    anser = 1

    t = 1
    while t * t <= g:
        if g % t == 0:
            s = g / t
            if IntegerN % t == 0:
                anser = max(anser, t)
            if IntegerN % s == 0:
                anser = max(anser, s)
        t += 1

print(anser)
0