UVA 495 Fibonacci Freeze 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 1501
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)
    {
        printf("The Fibonacci number for %d is ",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. Your Affiliate Money Making Machine is ready -

    Plus, making money with it is as simple as 1--2--3!

    Here's how it all works...

    STEP 1. Input into the system what affiliate products the system will push
    STEP 2. Add some PUSH BUTTON TRAFFIC (it ONLY takes 2 minutes)
    STEP 3. See how the system grow your list and sell your affiliate products all by itself!

    Are you ready??

    Click here to make money with the system

    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.