# Math Help - Calculating large powers, large modulo.

1. ## Calculating large powers, large modulo.

I'm able to get around the standard: x^a mod n.
But only when it's regarding relatively small variables.

But what method should I use to solve problems like: 33809^26767 mod 46927?

Should I use Euler's Totient somehow? If so, how?!

2. ## Re: Calculating large powers, large modulo.

How do you want to calculate this? I have a simple function that does the job.

3. ## Re: Calculating large powers, large modulo.

I'd like to calculated any way that's possible... Please share...

4. ## Re: Calculating large powers, large modulo.

It's crude but it works.

Code:
modpow(a,p,m)
{
k=1
v=a
while (2*k<p)
{
v=v^2 mod m
k*=2
}
while (k<p)
{
v=v*a mod m
k++
}
return v
}