結果

問題 No.443 GCD of Permutation
ユーザー mbanmban
提出日時 2017-07-26 07:19:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 811 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 69,320 KB
最終ジャッジ日時 2024-04-17 23:45:51
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 AC 42 ms
51,968 KB
testcase_03 WA -
testcase_04 AC 38 ms
52,096 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 38 ms
52,480 KB
testcase_08 WA -
testcase_09 AC 38 ms
52,096 KB
testcase_10 AC 36 ms
51,712 KB
testcase_11 WA -
testcase_12 AC 38 ms
52,224 KB
testcase_13 AC 37 ms
51,712 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 38 ms
51,968 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

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