結果

問題 No.443 GCD of Permutation
コンテスト
ユーザー ebicochineal
提出日時 2016-11-12 00:29:06
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 173 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 217,344 KB
最終ジャッジ日時 2026-05-20 01:09:22
合計ジャッジ時間 4,017 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 10 WA * 1 RE * 1 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def f(n):
    l = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            l += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : l += [n]
    return [1] + l

def g(a, b):
    r = []
    for i in a:
        if b % i == 0:
            r += [i]
            b //= i
    return r

gs = set([])
ga = 0
def p(s, ss):
    global ga
    if s == '':
        a = int(ss)
        gs.add(a)
        ga = a
    for i in set(s):
        p(s.replace(i, '', 1), ss+i)

def main():
    l = input()
    if len(set(l)) == 1:
        print(1)
        return
    
    s = set([])
    p(l,'')
    a = f(ga)
    for i in gs:
        a = g(a, i)
    ans = 1
    for i in a:
        ans *= i
    print(ans)

if __name__ == '__main__':
    main()
0