Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #define Nmax 500
- #define Rmax 420000
- using namespace std;
- int A[Nmax], B[Nmax], C[Nmax], Rez[Rmax],i, N, M, K;
- void adun(){
- int i=1, t=0;
- while (i<=A[0] || i<= B[0] || t>0)
- {
- t= A[i] + B[i] + t;
- C[i] = t % 10;
- t/=10;
- i++;
- }
- C[0] = i-1;
- }
- void swp (int X[Nmax], int Y[Nmax]){
- int i;
- for (i=1; i<=Y[0]; i++) X[i]=Y[i];
- X[0]= Y[0];
- }
- void taie(){
- int i=1, Nr=0, tai=0, Max , j, poz;
- i=1;
- for(i=1; i<=Rez[0] && Nr<=M; i++){
- Max = Rez[i];
- for (j=1; j<=M - Nr; j++)
- if (Rez[i + j * K] > Max) {
- Max = Rez[i + j * K];
- poz=i + j * K;
- tai=j;
- }
- if (Max > Rez[i]&& Nr<M){
- i = poz;
- Nr += tai;
- }
- printf("%d",Rez[i]);
- }
- }
- int main()
- {
- freopen("fibosir.in","r",stdin);
- freopen("fibosir.out","w",stdout);
- scanf("%d %d %d", &N, &M, &K);
- A[0]=1; A[1]=1; B[0]=1; B[1]=1; Rez[0]=2; Rez[1]=1; Rez[2]=1;
- for(i=3; i<=N; i++){
- adun(); swp(A,B); swp(B,C);
- reverse(C+1, C+C[0]+1);
- for (int t=1; t<=C[0]; t++) Rez[Rez[0]+t]=C[t];
- Rez[0]+=C[0];
- }
- taie ();
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement