結果
| 問題 | No.782 マイナス進数 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-11 22:16:00 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 637 bytes | 
| コンパイル時間 | 659 ms | 
| コンパイル使用メモリ | 68,224 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 08:19:46 | 
| 合計ジャッジ時間 | 2,408 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 36 | 
ソースコード
#include<iostream>
#include<algorithm>
using namespace std;
int p(int i, int j){
    int ret = 1;
    while(j-- > 0)  ret *= i;
    return ret;
}
int main(){
    int t, b, n;
    cin >> t >> b;
    while(t-- > 0){
        string res = "";
        cin >> n;
        int cnt = 0;
        while(n){
            int tmp = n%(p(-b, cnt+1));
            if(tmp < 0) tmp -= b;
            string add{(char)('0'+tmp)};
            res += add;
            n -= tmp;
            n /= b;
        }
        
        if(res == "")   res = "0";
        
        reverse(res.begin(), res.end());
        cout << res << endl;
    }
    return 0;
}
            
            
            
        