-1

I have to return $a^x b^y(mod p)$

However I'm having difficulty doing this with such large numbers.

I know I can change the format to $a b (mod p)^n$ and I will get a number however I'm just not sure how to work with different exponents, and numbers so large, and still get the correct answer.

$a = 1531201089928563$
$b = 5232015514746838$
$p = 36591670045183523$

$x = 31146826187279844$
$y = 1747419798738$

It is in computer programming. I'm just unsure of how to structure the formula correctly and would like some guidance.

Joffan
  • 39,627
Kenjii
  • 9

1 Answers1

0

First reduction: ensure $x,y$ are replaced by something less than $p$. This is by Fermat's theorem which states that $a^x=a^r\pmod p$ where $r$ is the remainder from $x$ when divided by $p-1$.

Next use the iterated squaring method: I'll sketch this. Normally to calculate $a^{41}$ one needs 40 multiplications. Iterated squaring exploits the binary representation, $41=32+8+1$. So $a^{41}= a^{32}\times a^8 \times a^1$. This requires 2 multiplications, to calculates $a^{32}$ repeatedly square $a$, and on the way you would also have computed $a^8$. (All this holds for mudular exponentiation. At every stage you can calculates the result mod p.