Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|cite|improve this question
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? – Karolis Juodelė Sep 7 '12 at 19:55
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? – Sasha Sep 7 '12 at 19:56
For $n=9$, the result is $\dfrac{6828}{5}$. Is there possibly a typo? – Kris Williams Sep 7 '12 at 19:59
@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 ? – Kyuubi Sep 7 '12 at 20:07
@Sasha : The values are only for n>3 – Kyuubi Sep 7 '12 at 20:07
up vote 1 down vote accepted

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 (

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

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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