結果
| 問題 | 
                            No.915 Plus Or Multiple Operation
                             | 
                    
| コンテスト | |
| ユーザー | 
                             nadare
                         | 
                    
| 提出日時 | 2019-10-25 22:15:32 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 443 bytes | 
| コンパイル時間 | 91 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2024-11-07 03:32:25 | 
| 合計ジャッジ時間 | 1,131 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 WA * 1 RE * 4 | 
ソースコード
def inpl(): return list(map(int, input().split()))
for _ in range(int(input())):
    a, b, c = inpl()
    if c == 1:
        print(a*b)
        continue
    Q = []
    ans = 0
    
    while a:
        a, m = divmod(a, c)
        Q.append(m)
    if (len(Q) >= 2) & (Q[-1] == 1) & (1 <= Q[-2] <= c-2):
        ans += 3
        Q.pop()
        Q.pop()
    
    while Q:
        x = Q.pop()
        ans += 1 + (x > 0)
    
    print(b*(ans-1))
            
            
            
        
            
nadare