Hat's Fibonacci

来源:互联网 发布:python sys.path 编辑:程序博客网 时间:2024/04/29 01:18
Problem Description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
 

Input
Each line will contain an integers. Process to end of file.
 

Output
For each case, output the result in a line.
 

Sample Input
100
 

Sample Output
4203968145672990846840663646
/*
解题报告:对大数的加法一段一段的加,也就是每8位看成一个整形的数(mod 10^9),进行整数加法。
*/
//标程:
#include<stdio.h>#include<string.h>#define  N  10000#define  M 300#define  pi 100000000int f[N][M];void fun(){    int i,j;    memset(f,0,sizeof(f));f[1][1]=f[2][1]=f[3][1]=f[4][1]=1;int k;for(i=5;i<N;i++){k=0;for(j=1;j<M;j++){k=k+f[i-1][j]+f[i-2][j]+f[i-3][j]+f[i-4][j]; f[i][j]=k%pi;            k=k/pi;}}}int main(){/// freopen("a.txt","r",stdin);fun();int n,i,j;while(scanf("%d",&n)!=EOF){  for(i=M-1;i>0;i--)  if(f[n][i]!=0) break;          printf("%d",f[n][i]); for(j=i-1;j>0;j--) printf("%08d",f[n][j]);  printf("\n");}return 0;}
0 0
原创粉丝点击