Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Brute Force O(N): store three variables, t1, t2, index. While an iterable i is smaller than index, change t2 to t1+t2 and t1 to the original value of t2. Return t2 at the end.
- A Pissano period is a period that occurs when you modulo all terms the fibonacci sequence. This is given by a function pi(x), where x is the modulo. However, it is not easy to calculate pi(1000000007) because it is too large.
- Optimized Brute Force: we can optimize the O(N) brute force by noting that if ever in our sequence that t1 = 0 and t2 = 1 and i != 1, this is the beginning of a new period. Therefore, we can modulo the remaining by the length of the period.
- By Lagrange's theorem and Fermat's little theorem, we can eventually prove that for every prime N where N is congruent to 2 mod 5, the N+1th fibonacci term is congruent to 0 mod N.
- Number Theory Method: at the start of the program, modulo the index by N+1 since the N+1th term will have t1 = 0 and t2 = 1.
- Theoretically, the above solution should work. For some unknown reason, it doesn't.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement