题目:http://codeforces.com/contest/1059/problem/C
题意:给出n,n个数分别为1—n
1.求出所有数的最大公因数
2.删除一个数
直到输出n个公因数结束。使得答案的字典序最大
思路:明显可以看出需要先删除奇数,如果先删除偶数得到的1的数量一定比删除奇数多。
此时需要手动模拟几个
1
1 2
1 1 3
1 1 2 4
1 1 1 2 4
1 1 1 2 2 6
1 1 1 1 2 2 6
1 1 1 1 2 2 4 8
发现:当删除完所有奇数时,可以得出最大公因数为t=2。此时如果剩余数目大于3,继续提出公因数2,t*=2,一直到n<=3为止,从前面3个例子看出有所不同,得出最后3个数的答案
n=1 ans:t
n=2 ans:t t2
n=3 ans:t t t3
#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> LP;
const ll inf = 1e17 + 10;
const int N = 1e6 + 10;
const ll mod = 1e9+7;
const int base=131;
const double pi=acos(-1);
map<string, int>ml;
map<ll,ll> mp;
map<int,int> vi;
priority_queue<P> q;
priority_queue<P> tq;
ll b[N], vis[N], dep[N],num[N], a[N],t, n, m, k,x,y;
int ex, ey, cnt, ans, sum, flag;
ll l[N],r[N],po[N];
//vector<int> v[N];
vector<int> fac[N];
string s;
map<int,int> dp[N];
char v[1005][1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
t=1;
while(n>3)
{
for(int i=1;i<=n-(n>>1);i++) cout<<t<<" ";
n>>=1;
t<<=1;
}
if(n==1) cout<<t<<endl;
else if(n==2) show2(t,t*2)
else show3(t,t,t*3);
}