結果
問題 | No.782 マイナス進数 |
ユーザー |
![]() |
提出日時 | 2019-01-11 22:08:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 904 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 194,396 KB |
最終ジャッジ日時 | 2025-01-06 20:20:05 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define repr(i, a, b) for(int i = a; i >= b; i--) #define int long long #define all(a) a.begin(), a.end() #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair<int, int> P; const int mod = 1000000007; const int INF = 1e18; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int t, b; cin >> t >> b; while(t--){ int n; cin >> n; if(n == 0){ cout << 0 << endl; continue; } string s = ""; int v = 1; while(n){ int tmp = n % abs(b); if(v == -1) tmp = (abs(b) - tmp) % abs(b); s += '0' + tmp; n -= v * tmp; n /= abs(b); v *= -1; } reverse(s.begin(), s.end()); cout << s << endl; } }