Friends please help me how can I perform (x^y - 1)%n | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Friends please help me how can I perform (x^y - 1)%n

Where x, y, n are very large numbers . I have used modular exponentiation , but it shows me wrong answer ! Plz give me a correct code !

18th Aug 2019, 5:49 PM
Eswar Kishore
Eswar Kishore - avatar
2 Answers
+ 2
If the number is larger than the data value can hold then you get an overflow and an incorrect result. If you’re using java try using long as your data type.
18th Aug 2019, 5:53 PM
Ole113
Ole113 - avatar
0
how to implement (x^y -1)%n .
13th Nov 2019, 5:49 PM
Eswar Kishore
Eswar Kishore - avatar