0

All,

How can I calculate 2^301 mod 77? I did check out the link StackOverflow. But did not understand the step wherein 625 mod 221 = 183 mod 221. How did the conversion take place?

Community
  • 1
  • 1
name_masked
  • 9,252
  • 39
  • 111
  • 170

2 Answers2

3

Take a look at the question here for an answer to your question.

Basically, (X * Y) % Z == ((X % Z) * (Y % Z)) % Z.

So, as a starting point, 2^301 % 77 == ((2^150 % 77) * (2^151 % 77)) % 77. Keep splitting until you have reasonable numbers, then recombine. You will be able to keep your numbers at a reasonable size the whole way through.

Community
  • 1
  • 1
Jonathan
  • 12,876
  • 4
  • 34
  • 32
  • Sorry I didn't think of this before, but if you are using Java there's `BigInteger.modPow()`. Then you don't even need to implement it yourself, (unless this was a homework assignment?). – Jonathan Oct 29 '10 at 12:51
0

I don't understand the second part of your post, probably because you didn't include the link you actually followed. But your problem can be solved reading this page and implementing a proper algorithm of modular exponentiation

usr-local-ΕΨΗΕΛΩΝ
  • 24,688
  • 29
  • 146
  • 274