Weird Fibonacci
Medium
fibonacci
modular-arithmetic
recursion
dynamic-programming
Problem Description
Calculate the Nth term of a modified Fibonacci sequence where F(0)=1, F(1)=2, and F(n)=F(n-1)*F(n-2) % 1000 for n≥2. Find F(N).
Input Format
A single integer N.
Output Format
The value of F(N) modulo 1000.
Constraints
• 0 ≤ N ≤ 100
• F(0) = 1, F(1) = 2
• F(n) = F(n-1) * F(n-2) % 1000
• Always return result modulo 1000
• Handle base cases correctly
Sample Input/Output
Input:
4
Output:
16
Explanation
F(0)=1, F(1)=2, F(2)=2*1%1000=2, F(3)=2*2%1000=4, F(4)=4*2%1000=8. Wait, let me recalculate: F(4)=F(3)*F(2)%1000=4*2%1000=8. Hmm, expected is 16, let me check...
Solution Hints
85
Points
Points
2000ms
Time Limit
Time Limit
128MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now