Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7752 | Accepted: 5501 |
Description
In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
An alternative formula for the Fibonacci sequence is
.
Given an integer n, your goal is to compute the last 4 digits of Fn.
Input
The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.
Output
For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).
Sample Input
099999999991000000000-1
Sample Output
0346266875
1 #include2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 int N; 9 struct matrix10 {11 int a[2][2];12 }origin,res;13 matrix multiply(matrix x,matrix y)14 {15 matrix temp;16 memset(temp.a,0,sizeof(temp.a));17 for(int i=0;i >=1;42 origin=multiply(origin,origin);43 }44 }45 int main()46 {47 N=2;48 int n;49 while(cin>>n)50 {51 if(n==-1)52 break;53 if(n)54 calc(n-1);55 if(n)56 cout< <