1 #include<stdio.h> 2 #define MAX 100000000 3 int a[MAX]; 4 int main() 5 { 6 int t,n; 7 int num=3; 8 a[0]=1;a[1]=2;a[2]=4; 9 while(1) 10 { 11 a[num]=(a[num-1]+a[num-2]+1)%10007; 12 if(a[num]==a[2]&&a[num-1]==a[1]&&a[num-2]==a[0]) 13 break; 14 num++; 15 }//求循环点的算法, 16 scanf("%d",&t); 17 while(t--) 18 { 19 scanf("%d",&n); 20 printf("%d\n",a[n%(num-2)]); 21 } 22 return 0; 23 }
Description |
Leyni has a strange dog called Vagaa and it is just born.(We call it 0 years old.)
1.Vagaa will lay a small dog each year till it is 2 years old.(It will lay when it's 2 years old and won't lay when it's 3 years old.)
2.Vagaa will live forever.(Because it believes in ChunGe.) 3.The same as its child.(Its child will lay and live as the same as Vagaa.)
For example,
0 year : 1 dog. (Vagaa(0 years old).) 1 year : 2 dog. (Vagaa(1 years old) and its child(0 years old).) 2 year : 4 dog. (Vagaa(2) and its child(1) will lay 2 dogs(0).) 3 year : 7 dog. (Vagaa(3) won't lay. Its child(2) will lay 1 dog(0). The other 2 dogs(1) will lay 2 dogs(0).) 4 year : 12 dog. (...)
Now, Leyni want to know how many dogs he has in total when Vagaa is N years old.
|
Input |
There are multiple test cases. The first line of input is an integer T indicating the number of test cases. Then T test cases follow. |
Output |
For each test case: |