結果

問題 No.443 GCD of Permutation
ユーザー rlangevinrlangevin
提出日時 2023-10-26 00:31:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 762 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 81,476 KB
実行使用メモリ 66,296 KB
最終ジャッジ日時 2023-10-26 00:31:19
合計ジャッジ時間 3,177 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,500 KB
testcase_01 AC 37 ms
53,508 KB
testcase_02 AC 38 ms
53,508 KB
testcase_03 AC 38 ms
53,508 KB
testcase_04 AC 38 ms
53,560 KB
testcase_05 AC 38 ms
53,508 KB
testcase_06 AC 39 ms
53,508 KB
testcase_07 AC 37 ms
53,560 KB
testcase_08 AC 37 ms
53,508 KB
testcase_09 AC 38 ms
53,508 KB
testcase_10 AC 38 ms
53,508 KB
testcase_11 AC 38 ms
53,508 KB
testcase_12 AC 39 ms
53,560 KB
testcase_13 AC 38 ms
53,508 KB
testcase_14 AC 38 ms
53,508 KB
testcase_15 AC 48 ms
62,156 KB
testcase_16 AC 49 ms
62,160 KB
testcase_17 AC 47 ms
62,212 KB
testcase_18 AC 55 ms
64,260 KB
testcase_19 AC 52 ms
62,212 KB
testcase_20 AC 52 ms
64,260 KB
testcase_21 AC 48 ms
62,212 KB
testcase_22 AC 38 ms
53,508 KB
testcase_23 AC 38 ms
53,508 KB
testcase_24 AC 38 ms
53,508 KB
testcase_25 AC 53 ms
64,248 KB
testcase_26 AC 54 ms
66,296 KB
testcase_27 AC 48 ms
62,160 KB
testcase_28 AC 51 ms
64,236 KB
testcase_29 AC 50 ms
64,204 KB
testcase_30 AC 51 ms
64,204 KB
testcase_31 AC 49 ms
64,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

def div(n):
    if n <= 0:
        return []
    S = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            S.add(i)
            S.add(n // i)
        i += 1
    return list(S)

n = input()
if len(set(n)) == 1:
    print(n)
    exit()
    
D = [0] * 10
for i in n:
    D[int(i)] = 1
    
g = -1
for i in range(10):
    for j in range(i + 1, 10):
        if D[i] and D[j]:
            if g == -1:
                g = 9 * (j - i)
            else:
                g = gcd(g, 9 * (j - i))
            
n = list(n)
n.reverse()
ans = 0
for d in div(g):
    ten = 1
    v = 0
    for s in n:
        v += ten * int(s)
        v %= d
        ten *= 10
        ten %= d
    if v == 0:
        ans = max(ans, d)
        
print(ans)
0