結果

問題 No.443 GCD of Permutation
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-11-10 08:32:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 979 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 64,320 KB
最終ジャッジ日時 2023-11-10 08:32:55
合計ジャッジ時間 3,326 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,736 KB
testcase_01 AC 40 ms
55,736 KB
testcase_02 AC 40 ms
55,736 KB
testcase_03 AC 42 ms
55,736 KB
testcase_04 AC 42 ms
55,736 KB
testcase_05 AC 42 ms
55,736 KB
testcase_06 AC 42 ms
55,736 KB
testcase_07 AC 41 ms
55,736 KB
testcase_08 AC 43 ms
55,736 KB
testcase_09 AC 40 ms
55,736 KB
testcase_10 AC 40 ms
55,736 KB
testcase_11 AC 41 ms
55,736 KB
testcase_12 AC 42 ms
55,736 KB
testcase_13 AC 42 ms
55,736 KB
testcase_14 AC 49 ms
64,056 KB
testcase_15 AC 56 ms
64,320 KB
testcase_16 AC 50 ms
64,320 KB
testcase_17 AC 52 ms
64,320 KB
testcase_18 AC 56 ms
64,312 KB
testcase_19 AC 48 ms
64,320 KB
testcase_20 AC 55 ms
64,312 KB
testcase_21 AC 51 ms
64,320 KB
testcase_22 AC 41 ms
55,736 KB
testcase_23 AC 40 ms
55,736 KB
testcase_24 AC 42 ms
55,736 KB
testcase_25 AC 57 ms
64,312 KB
testcase_26 AC 65 ms
64,312 KB
testcase_27 AC 55 ms
64,320 KB
testcase_28 AC 55 ms
64,312 KB
testcase_29 AC 65 ms
64,312 KB
testcase_30 AC 67 ms
64,312 KB
testcase_31 AC 58 ms
64,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

S = list(input())[:-1]
S = [int(s) for s in S]
N = len(S)

if len(set(S))==1:
    print(''.join(map(str,S)))
    exit()

X = set(S)

GG = []

n = len(X)
X = list(X)
X.sort()
for i in range(n-1):
    for j in range(i+1,n):
        GG.append(9*(X[j]-X[i]))

d= GG[0]
for g in GG:
    d = math.gcd(d,g)
    

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
    
P = make_divisors(d)

ans = 1
def is_ok(x):
    
    tmp = 0
    for i in range(N-1,-1,-1):
        tmp += S[i]*pow(10,N-1-i,x)
        tmp %= x
    return (tmp%x==0)

for p in P:
    if is_ok(p):
        ans = max(ans,p)
print(ans)
0