Fibbonacci Number(杭电2070)

/*Fibbonacci Number

Problem Description

Your objective for this question is to develop a program which will generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0

f(1) = 1

f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50.

Input

Each test case consists of one integer n in a single line where 0≤n≤50. The input is terminated by -1.

Output

Print out the answer in a single line for each test case.

Sample Input

3

4

5

-1

Sample Output

2

3

5

you can use 64bit integer: __int64
*/
#include<cstdio>
#include<string.h>
__int64 s[100]={0,1,0};
int main()
{
    int n,i;
    while(~scanf("%d",&n),n!=-1)
    {
       for(i=2;i<=n;i++)
       {
            s[i]=s[i-1]+s[i-2];
        }
        printf("%I64d\n",s[n]);
    }
    return 0;
}
时间: 2024-08-11 06:59:42

Fibbonacci Number(杭电2070)的相关文章

杭电(hdu)2070 Fibbonacci Number 水题

Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17675    Accepted Submission(s): 8422 Problem Description Your objective for this question is to develop a program which will g

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来...每道题都错好多次...很考察细节.比如这道....WA了无数次.... 这题的思路自己真心想不到...这题是将进制后的数分别是1位,2位,3位和更多位的分开来计算. 当是1位的时候,显然只有3到6,此时只能是-1 当是2位的时候,可以转换成一元一次方程求解 当是3位的时候,可以转换成一元二次方程求解 当是4位的时候,此时最多也只有7000个数,7000^3接近1e12.所以剩下的直接枚举进制数来判断即可. 代码如下: #include <i

杭电1212--Big Number

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5961    Accepted Submission(s): 4167 Problem Description As we know, Big Number is always troublesome. But it's really important in our

Number Sequence(杭电1005)

/*Number Sequence Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases.

杭电 1711 Number Sequence

Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10239    Accepted Submission(s): 4656 Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1],

杭电 HDU ACM 1212 Big Number

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5606    Accepted Submission(s): 3903 Problem Description As we know, Big Number is always troublesome. But it's really important in ou

HDU 2070 Fibbonacci Number

Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13400    Accepted Submission(s): 6677 Problem Description Your objective for this question is to develop a program which will g

HDUJ 2070 Fibbonacci Number

Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13234    Accepted Submission(s): 6628 Problem Description Your objective for this question is to develop a program which will g

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime