結果

問題 No.782 マイナス進数
ユーザー coco18000coco18000
提出日時 2019-01-11 21:56:34
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 3,015 ms
コンパイル使用メモリ 159,844 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 06:10:44
合計ジャッジ時間 3,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N[10005];
int T, B;

string binary(ll n)
{
    if (n == 0)
        return "0";
    string s = "";
    while (abs(n) > 0)
    {
        int t = n / B;
        int k = n - t * B;
        if (k < 0)
            k += abs(B);
        s += (char)('0' + k);
        n = (n - k) / B;
    }
    std::reverse(s.begin(), s.end());
    return s;
}
int main()
{
    cin >> T >> B;
    REP(i, T)
    {
        cin >> N[i];
    }
    REP(i, T)
    {
        cout << binary(N[i]) << endl;
    }
    return 0;
}
0