can anyone help me to find how many odd and even fibonacci number between n'th and m'th fibonacci number where the range of n and m is 10^18
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
can anyone help me to find how many odd and even fibonacci number between n'th and m'th fibonacci number where the range of n and m is 10^18
Name |
---|
odd + odd = even
odd + even = odd
even + odd = odd
F0 = 0, F1 = 1, F2 = 1, F3 = 2, ...
So every third number is even. You only need to count the number of numbers divisible by three in the interval.
More generally, If Fi is the smallest fibonacci number such that a | Fi, then a | Fj iff j = 0 (mod i). This holds since gcd(Fa, Fb) = F(gcd(a, b))
https://www.cut-the-knot.org/arithmetic/algebra/FibonacciGCD.shtml
i understand ur idea but can you help me by giving code of this please .
Instead, it is equivalent to the sum of all values in the fibonacci sequence between indicies n and m, and the fibonacci numbers are taken modulo 2. We can also form them (summing up) modulo 2. This can be used to count the number of odd values (for even, just taken m - n + 1 - countodd).
Instead of counting odds in the range, we can also count the odds in ranges [1, m] and [1, n — 1] and subtract the answers.
Let's form the first values of the fibonacci sequence modulo 2:
0 1 1 0 1 1 0 1 1 0 .... Notice that there's a cycle of length 3, of the form 0 1 1. We can use this property:
The number of odds in the range [1, x] (where 1 and x are indicies in the fibonacci sequence) is equal to:
Edit: you can also count instead the number of even values (which should be easier), as said in the comment above me.
thanks now i got it :D
Can you share the question link!!
https://www.devskill.com/CodingProblems/ViewProblem/389