we know that
(A + B) % P = (A % P + B % P) % P
(A * B) % P = (A % P * B % P) % P
where P
is a prime .
I need to calculate (A / B) % P
where A,B
can be very large and can overflow .
Does such kind of formula for modular arithmetic holds for (A / B) % P
and (A - B) % P
.
If not then please explain what the correct answer is.
I.e is it true that (A / B) % P = ((A % P) / (B % P)) % P
?
I WAS TRYING TO CALULATE (N*(N^2+5)/6)%P where N can be as large as 10^15
here A=n*(n^2+5) can surely overflow for n=10^15
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…