1
$\begingroup$

I have the following expression for $n>3$:

$$\frac{5\cdot(n-1)\cdot[8\cdot\operatorname{Luc}(n) + 5\cdot\operatorname{Luc}(n-1)] + [4\cdot\operatorname{Luc}(n-1) - 8\cdot\operatorname{Luc}(n)]}{25}$$

where $\operatorname{Luc}(n)$ gives the $n$th term in the Lucas sequence

$$ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, \dots $$starting from index $0$.

How do I reduce/rearrange it to remove the $25$ from the denominator? I need this so that I can take the modulus of the entire equation, without first doing any division. (The number in the numerator exceeds $2^{64}$, and I cannot store it in the memory)

$\endgroup$
  • 1
    $\begingroup$ If $25$ is coprime to $p$ (as in $\pmod{p}$), then $a/b \pmod{p} \equiv (a \pmod{p})/(b \pmod{p}) \pmod{p}$. Does that help? $\endgroup$ – Karolis Juodelė Sep 7 '12 at 19:55
  • $\begingroup$ Elements of the sequence $f_n = \frac{n-1}{5} \left( 8 L_{n} + 5 L_{n-1}\right) + \frac{4}{25} \left( 2 L_n - L_{n-1} \right)$ are not integral. For instance, $f_2 = \frac{33}{5}$. Are you expecting to end-up with $5$ in the denominator? $\endgroup$ – Sasha Sep 7 '12 at 19:56
  • $\begingroup$ For $n=9$, the result is $\dfrac{6828}{5}$. Is there possibly a typo? $\endgroup$ – Kris Williams Sep 7 '12 at 19:59
  • $\begingroup$ @KarolisJuodelė : the value of p = (10^9 + 7). Which is Coprime to 25. But How will this help ? if a = 150 , b = 25 and p =27 (p is coprime to b) , but (a/b)%p != ((a%p)/(b%p))%p . Or am I understanding the concept wrong ? $\endgroup$ – Kyuubi Sep 7 '12 at 20:07
  • $\begingroup$ @Sasha : The values are only for n>3 $\endgroup$ – Kyuubi Sep 7 '12 at 20:07
1
$\begingroup$

If you want to get the answer mod n, dividing by 25 is the same as multiply by the inverse of 25 mod n, which you can compute using extended GCD (http://en.wikipedia.org/wiki/Modular_multiplicative_inverse).

This requires that gcd(25,n)=1. If that is not the case, you're in trouble.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.