結果

問題 No.443 GCD of Permutation
ユーザー nola_suznola_suz
提出日時 2016-11-11 22:56:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 509 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 86,428 KB
最終ジャッジ日時 2024-05-04 02:34:42
合計ジャッジ時間 9,253 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,920 KB
testcase_01 AC 79 ms
76,504 KB
testcase_02 AC 78 ms
76,632 KB
testcase_03 AC 94 ms
76,960 KB
testcase_04 AC 118 ms
77,312 KB
testcase_05 AC 91 ms
76,372 KB
testcase_06 AC 91 ms
76,920 KB
testcase_07 AC 85 ms
76,812 KB
testcase_08 AC 89 ms
76,728 KB
testcase_09 AC 90 ms
76,528 KB
testcase_10 AC 88 ms
76,760 KB
testcase_11 AC 89 ms
77,132 KB
testcase_12 AC 89 ms
76,780 KB
testcase_13 AC 91 ms
76,872 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 111 ms
77,040 KB
testcase_17 AC 108 ms
77,612 KB
testcase_18 AC 741 ms
78,240 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 80 ms
76,844 KB
testcase_23 AC 82 ms
76,652 KB
testcase_24 AC 79 ms
76,772 KB
testcase_25 AC 818 ms
77,536 KB
testcase_26 AC 717 ms
77,416 KB
testcase_27 RE -
testcase_28 AC 366 ms
77,548 KB
testcase_29 AC 891 ms
78,008 KB
testcase_30 AC 867 ms
77,352 KB
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
n = input()
nn = len(n)
a = []
for i in n:
	a.append(i)
a.sort()
b = 0
for i in a:
	b *= 10
	b += int(i)
# print(b)
a.sort(reverse=True)
c = 0
for i in a:
	c *= 10
	c += int(i)
# print(c)

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

ans = gcd(b, c)
for i in range(60):
	for j in range(1000):
		aa = random.randint(0, nn-1)
		bb = random.randint(0, nn-1)
		a[aa], a[bb] = a[bb], a[aa]
	d = 0
	for i in a:
		d *= 10
		d += int(i)
	ans = gcd(ans, d)
print(ans)
0