Submission
Status:
-PPPPPPP-P
Subtask/Task Score:
80/100
Score: 80
User: Dormon
Problemset: เลขฐานเบญจภาคได้ดุล
Language: cpp
Time: 0.033 second
Submitted On: 2025-10-14 19:54:45
#include <iostream>
#include <vector>
using namespace std;
const vector<int> v = {-2, -1, 0, 1, 2};
vector<int> ans;
bool solve(int n, int s, int _5){
if (n == s){
// cout << n << ' ' << s << '\n';
for (auto e:ans)
cout << e << ' ';
cout << '\n';
return true;
}
if (_5 >= 5000) return false; // 5^6 > 5000
for (auto e:v){
ans.push_back(e);
if (solve(n, s + _5 * e, _5 * 5)) return true;
ans.pop_back();
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--){
int n;
cin >> n;
ans.clear();
solve(n, 0, 1);
}
}