Untitled
unknown
plain_text
16 days ago
2.1 kB
3
Indexable
Never
#include <bits/stdc++.h> using namespace std; #define int unsigned long long void __print(int x) { cerr << x; } void __print(unsigned x) { cerr << x; } // void __print(unsigned int x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif //precompute all per fect sqares till 1e5 void solve() { int n; cin >> n; vector <int> perfect; for(int i=1;i<=2*n;i++){ // perfect[i*i] = 1; perfect.push_back(i*i); } int nearest_square = 0; int pos = 0; for(int i=0;i<perfect.size();i++){ if(perfect[i]>=n){ nearest_square = perfect[i]; pos = i; break; } } debug(perfect); vector<int> a(n); int len = n; for(int i=n-1;i>=0;i--){ debug(i,nearest_square); if(nearest_square-i<len){ a[i]= nearest_square-i; } else{ nearest_square = perfect[pos-1]; pos--; len = i+1; i++; } } for(int i=0;i<n;i++){ cout << a[i] << " "; } cout << endl; } signed main() { int t = 1; // precompute(); cin >> t; while (t--) { debug(t); solve(); } return 0; }
Leave a Comment