-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path480-yet-another-permutation-problem.cpp
More file actions
50 lines (49 loc) · 1.12 KB
/
Copy path480-yet-another-permutation-problem.cpp
File metadata and controls
50 lines (49 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Yet Another Permutation Problem [1858C]
* Problem: https://codeforces.com/problemset/problem/1858/C
* Verdict: ACCEPTED Solved: 2023-08-15
* Language: C++17 (GCC 7-32)
* Runtime: 30 ms Memory: 900 KB
* Tags: constructive algorithms, greedy, math, number theory
* Author: BidoTeima
* Source: https://codeforces.com/contest/1858/submission/218982730
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 3;
int s[N];
int dp[N];
int n,m,d;
int rec(int i){
if(dp[i]!=-1)return dp[i];
if(i == m)
return 0;
return dp[i]= 1 + (s[i + 1] - s[i] - 1) / d + rec(i + 1);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool vis[n+1]{};
for(int i = 1; i <= n; i++){
if(vis[i])continue;
vis[i]=1;
int x = i;
cout<<x<<' ';
while(2*x<=n){
x*=2;
cout<<x<<' ';
vis[x]=1;
}
}
cout<<'\n';
}
return 0;
}