Submission
Status:
-TTTTTTTTT
Subtask/Task Score:
0/100
Score: 0
User: colo39
Problemset: เลขฐานเบญจภาคได้ดุล
Language: cpp
Time: 1.097 second
Submitted On: 2026-10-06 14:04:34
#include <bits/stdc++.h>
using namespace std;
int a[10];
int n;
int ch[] = {-2,-1,0,1,2};
vector<int> rst;
bool check = 0;
void sol(int now) {
if (check) return;
if (now == 8) {
int rs = 0;
for (int i = 1;i <= 7 ;i++) {
rs += pow(5,i-1) * a[i];
}
if (rs == n) {
for (int i = 1;i <= 7 ;i++) {
rst.push_back(a[i]);
}
check = 1;
}
return;
}
for (int i = 0;i < 5;i++) {
a[now] = ch[i];
sol(now+1);
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--) {
cin >> n;
//cout << "nigga";
sol(1);
bool ck = 0;
for (int i = rst.size() - 1 ;i >= 0;i--) {
if (ck == 0 && rst[i] == 0) {rst.pop_back();i = rst.size() - 1;}
if (ck == 0 && rst[i] != 0) ck = 1;
}
rst.pop_back();
for (auto i : rst) cout << i << " ";
cout << "\n";
check = 0;
rst.clear();
}
}