結果

問題 No.443 GCD of Permutation
ユーザー paruki
提出日時 2016-11-12 00:07:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 425 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-11-25 10:32:58
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 10 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import sys

def gcd(a, b):
	if a == 0:
		return b
	else:
		return gcd(b%a, a)

def lcm(a, b):
	return a*b//gcd(a,b)

s = input()
t = []
for c in s:
    if c!='0':
        t.append(int(c))
t=sorted(t)
x=0
for i in t:
    x=x*10+i
if t[0] == t[-1]:
    print(x)
    sys.exit()

nn = 0
m = len(t)
for i in range(m-1):
    nn = 9+10*nn

p = gcd(x, nn)
q = 0
for i in t:
    q=gcd(q,i)

ans = lcm(p,q)
print(ans)
0