Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Last active February 14, 2017 19:00
Show Gist options
  • Select an option

  • Save shohan4556/c04684a10efdfb63c8f2 to your computer and use it in GitHub Desktop.

Select an option

Save shohan4556/c04684a10efdfb63c8f2 to your computer and use it in GitHub Desktop.
uva 374
/// Author : Md. Shohanur Rahamana
// Uva - 374
// Problem Type : Same as Problem Name (Big Mod)
#include<stdio.h>
int long long bigmod(int long long a,int long long p,int long long m);
int main()
{
int long long a,p,m,res;
while(scanf("%lld",&a)==1){
scanf("%lld",&p);
scanf("%lld",&m);
res=bigmod(a,p,m);
printf("%lld\n",res);
}
return 0;
}
int long long bigmod(int long long a,int long long p,int long long m)
{
if(p==0)
return 1;
if(p%2==0){
int long long c=bigmod(a,p/2,m);
return c*c%m;
}
else
{
return (a * bigmod(a,p-1,m))%m;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment