Problem Type : Number Theory
#include<stdio.h>
int main()
{
long long a,b,m,a1,p,i;
while(scanf("%lld %lld %lld",&a,&b,&m)==3)
{
a1 = a %m;
p = 1;
while (b > 0)
{
if (b %2==1)
{
p *= a1;
p = p % m;
}
b /= 2;
a1 = (a1 * a1) % m;
}
printf("%lld\n",p);
}
return 0;
}
#include<stdio.h>
int main()
{
long long a,b,m,a1,p,i;
while(scanf("%lld %lld %lld",&a,&b,&m)==3)
{
a1 = a %m;
p = 1;
while (b > 0)
{
if (b %2==1)
{
p *= a1;
p = p % m;
}
b /= 2;
a1 = (a1 * a1) % m;
}
printf("%lld\n",p);
}
return 0;
}
No comments:
Post a Comment