結果

問題 No.443 GCD of Permutation
ユーザー parukiparuki
提出日時 2016-11-12 00:07:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 425 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-05-04 03:53:08
合計ジャッジ時間 1,934 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 27 ms
10,880 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 26 ms
10,752 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 25 ms
10,752 KB
testcase_11 WA -
testcase_12 AC 25 ms
10,752 KB
testcase_13 AC 26 ms
10,752 KB
testcase_14 RE -
testcase_15 WA -
testcase_16 AC 27 ms
10,752 KB
testcase_17 AC 29 ms
10,752 KB
testcase_18 AC 53 ms
11,136 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 53 ms
10,880 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 26 ms
10,752 KB
testcase_29 RE -
testcase_30 AC 56 ms
11,008 KB
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

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