結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2016-11-14 22:57:23 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 121 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-11-26 01:26:03 |
合計ジャッジ時間 | 2,043 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | AC * 1 RE * 27 |
ソースコード
#!/usr/bin/env python3 import fractions import functools import itertools def divisors(n): for i in range(1, n): if i * i > n: break elif n % i == 0: yield i yield n // i 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(fractions.gcd, xs) if g == 0: return n else: return max(f for f in divisors(g) if n % f == 0) def main(): print(gcd_of_permutations(int(input()))) if __name__ == '__main__': main()