結果

問題 No.782 マイナス進数
ユーザー addeight2
提出日時 2019-02-08 11:30:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 161,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 15:45:53
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
ll T,B;
vector<ll> ans;
int main(){
	cin>>T>>B;
	B*=-1;
	REP(q,T){
		ll N;
		cin>>N;
		ans.clear();
		while(N){
			ll a=N%B;
			a=(a+B)%B;
			N=-(N-a)/B;
			ans.push_back(a);
		}
		reverse(ans.begin(),ans.end());
		for(auto a:ans){
			cout<<a;
		}
		if(ans.size()==0){
			cout<<0;
		}
		cout<<endl;
	}
}
0