結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 16:46:23 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 556 bytes | 
| コンパイル時間 | 231 ms | 
| コンパイル使用メモリ | 82,560 KB | 
| 実行使用メモリ | 62,720 KB | 
| 最終ジャッジ日時 | 2025-06-12 16:46:53 | 
| 合計ジャッジ時間 | 2,584 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 23 WA * 5 | 
ソースコード
import sys
import math
def all_same(s):
    return all(c == s[0] for c in s)
def main():
    s = sys.stdin.readline().strip()
    if all_same(s):
        print(s)
        return
    # Compute sum of digits
    total = sum(int(c) for c in s)
    # Compute GCD of non-zero digits
    g = 0
    for c in s:
        d = int(c)
        if d != 0:
            if g == 0:
                g = d
            else:
                g = math.gcd(g, d)
    # Compute P and G
    P = g * 9
    G = math.gcd(total, P)
    print(G)
if __name__ == "__main__":
    main()
            
            
            
        