UVA 10579 Fibonacci Numbers Solution

   Solution in c++:
     ///**********ALLAH IS ALMIGHTY************///
     ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
#define lim 50000
#define len 1001
long long fib[lim][len],i,j;
void fibonacci()
{
    fib[0][0]=0;
    fib[1][0]=1;
    fib[2][0]=1;
    for(i=3;i<lim;i++)
    {
        for(j=0;j<len;j++)
        {
            fib[i][j]+=fib[i-2][j]+fib[i-1][j];
            if(fib[i][j]>9)
            {
                fib[i][j+1]+=fib[i][j]/10;
                fib[i][j]=fib[i][j]%10;
            }
        }
    }
}
main()
{
    fibonacci();
  long long n;
  while(cin>>n)
    {
        for(i=len-1;i>0;i--)
        {
            if(fib[n][i]!=0)
            {
                break;
            }
        }
        for(;i>=0;i--)
        {
             cout<<fib[n][i];
        }

        cout<<endl;
    }

}

1 comment:

  1. As reported by Stanford Medical, It is in fact the one and ONLY reason women in this country get to live 10 years longer and weigh 19 KG less than us.

    (And realistically, it is not related to genetics or some secret exercise and really, EVERYTHING about "HOW" they are eating.)

    BTW, I said "HOW", not "WHAT"...

    Click on this link to find out if this short questionnaire can help you decipher your true weight loss possibilities

    ReplyDelete

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.