結果
| 問題 | No.782 マイナス進数 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-11 22:04:08 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 29 ms / 2,000 ms | 
| コード長 | 585 bytes | 
| コンパイル時間 | 1,626 ms | 
| コンパイル使用メモリ | 167,252 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 06:58:57 | 
| 合計ジャッジ時間 | 3,214 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 36 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T, B;
    cin >> T >> B;
    for (int i = 0; i < T; i++) {
        ll n;
        cin >> n;
        if (n == 0) {
            cout << 0 << endl;
            continue;
        }
        string ans = "";
        while (n != 0) {
            int d = ((n % -B) - B) % -B;
            n -= d;
            ans += (char)('0' + d);
            n /= B;
        }
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }
    return 0;
}
            
            
            
        