Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int Exmod(int a,int b,int c){
- if(b==0)
- return 1;
- else if(b%2==0){
- int d = Exmod(a,b/2,c);
- return (d*d)%c;///for (a^b/2%c)*(a^b/2%c)%c here two part are same
- ///so you should return (a^b/2%c)^2 then %c.
- }
- else {
- return ((a%c)*Exmod(a,b-1,c))%c;
- }
- }
- int main()
- {
- int a,b,c,result;
- scanf("%d%d%d",&a,&b,&c);
- result = Exmod(a,b,c);
- printf("result is : %d\n",result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment