思路
- 我们可以将n很小的时候按照斐波那契数列填充
又因为数不能大于1e9,所以我们可以先把前面满足的斐波那契数列逆序输出,之后填充“1”即可满足hack条件
代码
// Problem: 牛牛想要成为hacker
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9982/J
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=100010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
int a[N];
void solve(){
int n;cin>>n;
a[1]=a[2]=1;
if(n<=44){
cout<<"1 1 ";
rep(i,3,n){
a[i]=a[i-1]+a[i-2];
cout<<a[i]<<" \n"[i==n];
}
}
else{
vector<int> g;
g.pb(1);g.pb(1);
rep(i,3,34){
a[i]=a[i-1]+a[i-2];
g.pb(a[i]);
}
reverse(g.begin(),g.end());
rep(i,35,n) g.pb(1);
for(int x:g) cout<<x<<" ";
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;cin>>t;while(t--)
solve();
return 0;
}