Блог пользователя prathams

Автор prathams, история, 7 лет назад, По-английски

How to calculate the fibonacci entry point for N numbers p1, p2, p3, ...., pn. (1 <  = pi <  = 109)

FEP(pi) = j such that jth fibonacci number is the first fibonacci number Fj divisible by pi

How can we find it efficiently for N numbers.

Ex,
input = 2, output = 3
input = 5, output = 5
input = 13, output = 7

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If p is prime, the answer is divisor of p + 1 (except when p = 5). So check all p + 1 divisors with fast matrix power algorithm.

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

    If p = 11, answer is 10. 10 is not divisor of 12. And what if p is not prime.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Looks like it could be divisor of p − 1 too. Could be dependent on whether square root of 5 exists (that's why p = 5 is an exception) which is true if and only if p = 5n ± 1. For non-prime modulos you will need to combine answers with lcm for several powers of primes. To calculate the answer for the power of prime, you will need to check whether you need to multiply by p the answer for smaller power of prime.