結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 16:37:48 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 759 bytes | 
| コンパイル時間 | 217 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 62,976 KB | 
| 最終ジャッジ日時 | 2025-06-12 16:37:51 | 
| 合計ジャッジ時間 | 2,525 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 WA * 6 | 
ソースコード
import math
def compute_gcd(n_str):
    # Check if all characters are the same
    if all(c == n_str[0] for c in n_str):
        return n_str
    
    # Compute sum of digits
    s = sum(int(c) for c in n_str)
    
    # Compute minimal element m
    digits = sorted(n_str)
    # Find the first non-zero digit
    first_non_zero = next(i for i, d in enumerate(digits) if d != '0')
    # Form the minimal element
    minimal_digits = [digits[first_non_zero]] + digits[:first_non_zero] + digits[first_non_zero+1:]
    m_str = ''.join(minimal_digits)
    
    # Compute m mod s
    mod = 0
    for c in m_str:
        mod = (mod * 10 + int(c)) % s
    
    # GCD of s and mod
    g = math.gcd(s, mod)
    return str(g)
n = input().strip()
print(compute_gcd(n))
            
            
            
        