How is it possible to calculate modulo of the following equation:
$3^{P^5} \mod P$
If $P$ is a really big prime number 174449211009120179071170527.
Thanks
How is it possible to calculate modulo of the following equation:
$3^{P^5} \mod P$
If $P$ is a really big prime number 174449211009120179071170527.
Thanks
To find $a^M$ mod$p$, first write $M$ in binary, i.e. $$M=c_0+c_1 \times 2 + c_2 \times 2^2 + ... +c_n \times 2^n, c_i=0 \text { or }1,0 \le i\le n $$ The $c_i$ are easy to calculate-just keep dividing by 2 and taking the remainder. Then $$a^M=a^{c_0} \times a^{c_1 \times 2} \times a^{c_2 \times 2^2} \times ... \times a^{c_n \times 2^n}$$ and $$a^M \mod p=a^{c_0} \mod p \times a^{c_1 \times 2} \mod p \times a^{c_2 \times 2^2} \mod p\times ... \times a^{c_n \times 2^n}\mod p$$. Note that $$a^{2^{i+1}}=(a^{2^i})^2$$ and $$a^{2^{i+1}}\mod p=(a^{2^i}\mod p)^2$$ Thus all you need to do is start with $result$ as 1 and $powerofa$ as $a$ and keep track of $powerofa= a^{2^i}$, each time squaring the previous $powerofa$ and leaving the previous $result$ as is if $c_i=0$ or multipling it by $powerofa$ if $c_i=1$, making all calculations mod $p.$ Such a program is easy to write in the language of your choice, fast to execute and uses little storage space.
P=174449211009120179071170527;lift(Mod(3,P)^(P^5))
evaluates to $3$. Same thing with P^2 or P^3, etc. – Somos Mar 05 '20 at 20:56$\large \bmod p!:,\ 3^{\large:! p-1}!\equiv 1,\Rightarrow, 3^{:!\large p^{\Large 5}}!!\equiv 3^{:!\large p^{\Large 5}\bmod p-1}!\equiv 3^{\large 1^{\Large 5}}!!\equiv 3\ $ by $\large\bmod p!-!1!:,\ \color{#c00}{p\equiv 1},\Rightarrow, \color{#c00}p^{\large 5}\equiv \color{#c00}1^{\large 5}\ \ \ $
– Bill Dubuque Mar 05 '20 at 21:49