Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Imorange

Problemset: เลขฐานเบญจภาคได้ดุล

Language: cpp

Time: 0.005 second

Submitted On: 2026-01-11 11:45:04

#include <bits/stdc++.h>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	int tag = 1;
	if(n < 0){
		tag = -1;
		n = -n;
	}
	int carry = 0;
	if(n == 0){
		cout << 0 << '\n';
		return;
	}
	while(n > 0)
	{
		int y = n%5+carry;		
		if(y < 3){
			cout << tag*y << ' ';
			carry = 0;
		}else{
			cout << -tag * (5-y) << ' ';
			carry = 1;
		}
		n/=5;
	}
	if(carry > 0) cout << tag * carry;
	cout << '\n';
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		solve();
	}
}