Page 2 of 2

Uva Problem 900

Posted: Sat Oct 06, 2012 11:03 am
by mainul07

Code: Select all

#include<iostream>
using namespace std;
int main()
{
    long long int n,i,a[100000];
    while(cin>>n)
    {
        if(n==0)
        break;
        a[1]=1;
        a[2]=2;
        for(i=3;i<=n;i++)
        a[i]=a[i-1]+a[i-2];
        cout<<a[n]<<endl;
    }
    return 0;
}

It show time limit exceded please help me ... :wink:

Re: Uva Problem 900

Posted: Sun Oct 07, 2012 7:33 pm
by brianfry713
Precompute the results for n=1 through 50.