E FibonacciLand
Time Limit:1000MS Memory Limit:65535K
题型: 编程题 语言: 无限制
描述
Zayhero like travelling very much, and his current stop is FibonacciLand. FibonacciLand consist of total n (n = 10^k, 1 <= k <= 10^6) islands (index begins at 0). When Zayhero is doing sightseeing there, he need to move between different islands, however, there is a rule he must follow: Let’s say Zayhero has finish i moves after he arrive FibonacciLand. In the (i+1)-th move, he can only go to the (Fib(i+ 1) % n)-th island. And Zayhero starts at island 0. Fib(i) means the i-th element of Fibonacci Sequence. Which means: Fib(0) = 0 Fib(1) = 1 Fib(i) = Fib(i - 1) + Fib(i -2) (i >= 2) For example, assume n = 10, since Zayhero starts at 0 (which he finish 0 move), his next move is Fib(1) % n = 1, so he moves to island 1. In his 2nd move, he move to Fib(2) % n = 1 (yes, again), then 2, 3, 5, 8, 3, 1, etc. Being an experience ACMer, Zayhero is able to tell he will eventually repeat his moves. For the case above, after he finishes his 60th moves, he will start repeating his moves once again. Since he already know the n, so he want to know about how many steps, he will start repeating his moves again. Now is your turn to solve this problem. Since the result will be very huge, so you just need to output the result % (10^9 + 9).
输入格式
The first line of input consist of only 1 integer T (T <= 10^5), indicate the number of test cases. Then T lines follow, each line consist of 1 integer k (1 <= k <= 10^6), indicate there are n = 10^k islands in FibonacciLand.
输出格式
For each test case, print “Case #x: y”, x means the index of test case (starts from 1) and y means the number of moves when Zayhero starts reporting his moves, mod 10^9 + 9.
输入样例
3 1 2 3
输出样例
Case #1: 60 Case #2: 300 Case #3: 1500
题目意思就是找n使得fn的后k位为0,fn+1的后k位为1;
k从1到10,通过程序可以找出n的规律,发现:60,300,150,1500,15000,150000,1500000,15000000,150000000....
易知规律
#include <iostream> #include <cmath> #include <stdio.h> #include <map> #include <string> #include <string.h> #include <algorithm> #include <queue> using namespace std; #define REP(i,a,b) for(int i=a;i<b;++i) #define scan(a) scanf("%d",&a) #define maxn 1000005 #define mset(a,b) memset(a,b,sizeof a) #define LL long long //#define mod 10000000000000000 const LL mod = 1000000009; LL ans[maxn]; int main() { ans[1]=60; ans[2]=300; ans[3]=1500; REP(i,4,maxn) { ans[i]=ans[i-1]*10; ans[i]%=mod; } int t,k; cin>>t; REP(cas,1,t+1) { scan(k); printf("Case #%d: %lld\n",cas,ans[k]); } }