I know the algorithm finding $ (a^b) mod\;n $ avoiding large numbers so I can code it, but I'm wondering if anyone can help me with a similar algorithm for $$ (a\cdot b^c )mod\;n $$ It's quite hard to search for. I'd like to code it in C++ so not storing numbers bigger than $2^{64}$. I'd be using values of $a,b$ and $c$ between 10 and 100, if that's useful?
2026-04-13 01:27:09.1776043629
On
Modulus algorithm for finding a*b^c mod n, avoiding large numbers?
244 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
2
On
You want the method of squaring and multiplying, remembering that you can reduce modulo $n$ after every multiplication (or squaring). You never need a number bigger than $n^2$ at any stage, so your storage restrictions are no hindrance.
A few things come to mind: