ASCDFIB - Ascending Fibonacci Numbers
John is trying to learn the Fibonacci sequence. This is what he has learned so far. The first two terms of the sequence are f(1) = 0 and f(2) = 1. The next term f(n) is then calculated by adding the previous two terms f(n-1) and f(n-2). Therefore,
f(1) = 0
f(2) = 1
f(3) = f(2) + f(1) = 1 + 0 = 1
f(4) = f(3) + f(2) = 1 + 1 = 2
f(5) = f(4) + f(3) = 2 + 1 = 3
f(6) = f(5) + f(4) = 3 + 2 = 5
After calculating this for a while, John realized that the values are becoming too big. In order to keep the values small, John changed his algorithm. Instead of calculating f(n) = f(n-1)+f(n-2), he decided he will calculate f(n) = ( f(n-1)+f(n-2) ) % 10^5.
Now John wants to do some research on his new modified Fibonacci sequence. He will give you an integer A (A<=10^5) and an integer B (B<=10^6). You have to output all the terms from f(A) to f(A+B) in ascending order (non-decreasing order). But printing so many numbers is too much of a hassle. So, if there are more than 100 terms in the output, then only print the first 100.
Input
The first line contains an integer T (T<=100), which is the number of test cases.
Each test case contains two positive integers A and B as mentioned before.
Output
For each test case, print case number (Check sample output) and then print the terms from f(A) to f(A+B) in ascending order (non-decreasing order). If there are more than 100 terms in the output, then only print the first 100.
Example
Input: 3 1 3 3 3 100 1 Output: Case 1: 0 1 1 2 Case 2: 1 2 3 5 Case 3: 15075 69026
hide comments
__hk__:
2015-06-05 15:07:46
Finally Got AC..!!! |
|
rladeira:
2015-06-01 04:13:21
Actually, I was missing the fact that the statement modified the classic definition of fibonacci numbers a little bit (considering f(1) = 0). However, I am now getting a TLE. I'll describe my approach and hopefully someone will be able to help me. =)
|
|
scyth3r:
2015-05-31 08:17:27
rladeira argument is legit to an extend!!!
|
|
kartikay singh:
2015-05-20 17:11:52
After 3WA and 2TLE
|
|
rladeira:
2015-05-17 18:33:32
I am wondering if the output of the "100 1" case isn't wrong. Fib(99) = 218922995834555169026, why the 69026 is showing up as part of the answer, since, as far as I understood, we should computing "Fib(100) mod 10^5" and "Fib(101) mod 10^5" ? Fib(99) mod 10^5 should not be printed for "100 1" case, but instead for "99 1" case. Last edit: 2015-05-17 18:57:20 |
|
MKM:
2015-01-28 15:22:14
learned a lot! |
|
AlcatraZ:
2014-10-10 00:07:22
This was my 7th question which i had attempted on spoj with an extremely naive algorithm(didnt even know mergesort) 1 year ago and got TLE .. Now i solved this as my 200th problem on spoj and AC in 1st go.. :) |
|
Bharath Reddy:
2014-09-22 09:36:31
C++ STL :D |
|
THE_SCORPION:
2014-08-25 22:35:13
giving SIGSEGV ??????? |
|
waddlepoof:
2014-06-26 15:25:03
Nice problem, getting the right indices of the sequence was the hardest thing. |
Added by: | forthright48 |
Date: | 2013-09-13 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Editorial |