結果

問題 No.443 GCD of Permutation
ユーザー lam6er
提出日時 2025-04-16 00:09:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 622 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 63,624 KB
最終ジャッジ日時 2025-04-16 00:10:20
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = input().strip()

if len(set(n)) == 1:
    print(n)
else:
    s = sum(int(c) for c in n)
    d = math.gcd(s, 9)
    
    # Check for factor2
    has_odd = any(int(c) % 2 != 0 for c in n)
    if has_odd:
        factor2 = 1
    else:
        factor2 = 2
        # Check if all even digits are 0,4,8
        allowed_even = {'0', '4', '8'}
        if all(c in allowed_even for c in n):
            factor2 *= 2
    
    # Check for factor5
    allowed_five = {'0', '5'}
    if all(c in allowed_five for c in n):
        factor5 = 5
    else:
        factor5 = 1
    
    g = d * factor2 * factor5
    print(g)
0