The Fibonacci sequence is a well known sequence of numbers in which
Given a number
, find the
Fibonacci number, modulo
.
Note: For 30% of the marks of this problem, it is guaranteed that .
Input Specification
The first line of input will have the number .
Output Specification
The Fibonacci number, modulo
.
Sample Input
26
Sample Output
121393
Comments
I used dp but doesn't work with larger inputs, I need to use bitnet or what?
You'll need to take a fundamentally different approach-
is too slow for this problem.
What are we trying to solve? Sry I'm new to Dmoj so it's kinda confusing.
Given a number
, find the
th Fibonacci number, modulo
.
Note that
can be very large - 
Any ideas on how to cut down on the recursive calls and avoid a stack overflow on the last case?
Edit: Avoid MLE
Try Solving the Fibonacci Sequence with Matrix Exponentiation
If im reading your code, you are reading in a long while the max value is above a long. Avoid using a long for input.
What should I use for input then?
You can read the input using unsigned long long.
Ah, it worked, thanks!
For some reason, my code doesn't work on this platform but it does on every other platform and all my test cases are right.
You should try testing your code with large test cases. For example,
.
The
overflowed my scanf need to use
scanf("%llu",&n);
This comment is hidden due to too much negative feedback. Show it anyway.
The intended solution uses matrices which is considered advanced math for DMOJ tags.
This comment is hidden due to too much negative feedback. Show it anyway.
r3mark hijacked global smurf cuz he submiited some 15+ pointers on it.
The problem requires you to output mod
. That means that you need to get the remainder of the final answer when it is divided by
. This operation can be done in Python, C++, and Java by using
%
.It may interest you to know that
is a prime number.
There are two highly useful properties of modular arithmetic we often use in programming competitions (
%
has the same precedence as multiplication and division):This problem is a lot more difficult than it may appear. There is a reason for 15 points. The input can be as big as
.
This comment is hidden due to too much negative feedback. Show it anyway.
The typical dynamic programming solution will not pass the larger inputs. More math insights is used in the solution rather than dynamic programming.