Codeforces Round #514 (Div. 2) C. Sequence Transformation

地址:http://codeforces.com/contest/1059/problem/C

受上一题影响,这道题刚开始看错题,上一题还没解决,自己不想做这道题,1到n,gcd应该是1,2,4,8。。。。应该让2,4…尽早提前出现,所以每次去掉n - (n / 2),gcd才会更新,还有要注意最后n 为 2 和 3比较小的情况,n 为 2 可以继续去,n为3要特判一下,因为输出最大的时候就不是2的幂次了。。。。。。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    int n;
    cin >> n;
    int x = 1;
    while(n)
    {
        for(int i = 1;i <= n - (n / 2);++i) cout << x << " ";
        if(n == 3){
            cout << 3 * x << " ";
            break;
        }
        n = n / 2;
        x *= 2;
    }
    cout << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36386435/article/details/82949291