Last active
February 14, 2017 19:00
-
-
Save shohan4556/c04684a10efdfb63c8f2 to your computer and use it in GitHub Desktop.
uva 374
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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