結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-11-10 08:32:52 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 75 ms / 1,000 ms | 
| コード長 | 979 bytes | 
| コンパイル時間 | 190 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 64,256 KB | 
| 最終ジャッジ日時 | 2024-09-26 00:42:52 | 
| 合計ジャッジ時間 | 3,494 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 28 | 
ソースコード
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)
            
            
            
        