A collection of codes containing the solution you are looking for.
A collection of codes containing the solution you are looking for.
function power_mod_q(x,n,q)
{
//Logic
if(n === 0)
return 1;
if(n % 2 === 0)
return power_mod_q((x * x) % q, n / 2, q);
else
return (x * power_mod_q((x * x) % q, n / 2, q)) % q;
}