結果

問題 No.443 GCD of Permutation
ユーザー はむ吉🐹
提出日時 2017-01-03 21:39:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 434 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-09-13 03:03:10
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import fractions
import functools
import itertools
import math

def gcd_of_permutations(n):
    if n < 10:
        return n
    ds = {int(d) for d in str(n)}
    xs = (9 * abs(a - b) for a, b in itertools.combinations(ds, 2))
    g = functools.reduce(math.gcd, xs, 0)
    return math.gcd(g, n) if g != 0 else n


def main():
    print(gcd_of_permutations(int(input())))


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