1732 Fibonacci Series 2
time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingTitle Description
Description
In the "1250 Fibonacci series", we find the value of the nth Fibonacci series. But in 1250, n<=109. Now, your task is still to find the value of the nth Fibonacci sequence, but note that n is an integer and 1 <= n <= 100000000000000
Enter a description
Input Description
Enter multiple sets of data, one row for each group of data, and an integer n (1 <= n <= 100000000000000)
Output description
Output Description
Outputs several rows. Output per line (corresponding input) n Fibonacci number (considering the number will be very large, mod 1000000007)
Sample input
Sample Input
3
4
5
Sample output
Sample Output
2
3
5
Data range and Tips
Data Size & Hint
1 <= N <= 100000000000000
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 using namespacestd;6 Long Longtable[2][2],a[2][2],h[2][2];7 intq=1000000007;8 voidFang ()9{intI,j,k; Memset (A,0,sizeof(a));Ten for(i=0; i<=1;++i) One for(j=0; j<=1;++j) A for(k=0; k<=1;++k) -A[i][j]= (A[i][j]+table[i][k]*table[k][j])%Q; - } the voidChengxa () -{intI,j,k; memset (H,0,sizeof(h)); -table[0][0]=0; table[0][1]=1; table[1][0]=1; table[1][1]=1; - for(i=0; i<=1;++i) + for(j=0; j<=1;++j) - for(k=0; k<=1;++k) +H[i][j]= (H[i][j]+table[i][k]*a[k][j])%Q; A for(i=0; i<=1; ++i) for(j=0; j<=1; ++j) table[i][j]=H[i][j]; at } - voidChangeback () -{inti,j; - for(i=0; i<=1; ++i) for(j=0; j<=1; ++j) table[i][j]=A[i][j]; - } - voidChengLong Longx) in { - if(x<=1)return; toCheng (x/2); + Fang (); - if(%2==1) Chengxa (); the ElseChangeback (); * } $ intMain ()Panax Notoginseng { - Long LongN; the while(cin>>N) + { Atable[0][0]=0; table[0][1]=1; table[1][0]=1; table[1][1]=1; theCheng (n1); printf"%lld\n", table[1][1]); + } - return 0; $}
View Code
codevs1732 Fibonacci Series 2 The Fool can no longer fool the moment multiply, but I also WA!