Number of Dafipo
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11520 Accepted Submission (s): 3911
The problem Descriptionfibonacci sequence is defined as follows:
F (1) =f (2) =1
F (n) =f (n-1) +f (n-2) n>=3.
Calculates the Fibonacci value of the nth item.
Input inputs The first behavior of an integer n, followed by n behavior integer Pi (1<=pi<=1000).
The output outputs are n lines, and the corresponding F (Pi) for each behavior.
Sample Input512345
Sample Output11235
another large number of questions;
ps:http://acm.hdu.edu.cn/showproblem.php?pid=1715
test instructions is very clear, is to seek Fibonacci series,
Some Java considerations,
See: Http://www.cnblogs.com/yuyixingkong/p/3919899.html
Importjava.math.*;ImportJava.util.*; Public classMain1715 {//Remember to change the name of the class to Main,,, the amount, said that his careless handed over 3 times ... Public Static voidMain (String args[]) {BigInteger f[]=Newbiginteger[1001] ; f[1]=NewBigInteger ("1"); f[2]=NewBigInteger ("1"); for(inti=3;i<=1000;i++) {F[i]=f[i-1].add (F[i-2]);//Add for the addition of large numbers;} Scanner SC=NewScanner (system.in); intN; intPi; N=Sc.nextint (); while(n-->0) {Pi=Sc.nextint (); System.out.println (F[pi]); } }}
In addition also useful C do, can reference!
#include <stdio.h>#include<string.h>Chars[1005][1005];intMain () {intI,j,wei,c,n; memset (s),'0',sizeof(s));//initializing an arrays[0][0]='0'; s[1][0]='1'; s[2][0]='1'; Wei=1;//number of control bits for(i=3; i<=1001; i++)//control number of rows { intHe//two number of combined andwei++;//number of control columnsC=0;//the initial value of the Carry index for(j=0; j<=wei;j++)//loops that control the number of columns{He=s[i-1][j]-'0'+s[i-2][j]-'0'+C; C=he/Ten;//Full 10 roundingS[i][j]=he%Ten+'0';//If you are over 10, you will be } } while(SCANF ("%d", &n) = =1) { inti; for(i=1; i<=n;i++) { intt=1001, A,j; scanf ("%d",&a); while(t--) { if(s[a][t]!='0')//search for the first character not ' 0 ' from the start Break; } for(j=t;j>=0; j--)//output from backward forwardprintf"%c", S[a][j]); printf ("\ n"); } }}
View Code
Number of Dafipo (Fibonacci) Java large number (hdu1715)