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

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.