結果
| 問題 | No.782 マイナス進数 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-08-01 22:52:58 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 609 bytes | 
| コンパイル時間 | 660 ms | 
| コンパイル使用メモリ | 71,320 KB | 
| 最終ジャッジ日時 | 2025-01-12 12:55:33 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 36 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
void solve() {
    int q, b;
    std::cin >> q >> b;
    while (q--) {
        int n;
        std::cin >> n;
        std::string ans;
        while (n != 0) {
            int d = 0;
            while ((n - d) % (-b) != 0) ++d;
            ans.push_back('0' + d);
            n = (n - d) / b;
        }
        std::reverse(ans.begin(), ans.end());
        if (ans.empty()) ans.push_back('0');
        std::cout << ans << "\n";
    }
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
            
            
            
        