Implement Program 01 :
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
#include<stdio.h> | |
int bigmod(int a,int p,int m); | |
int main() | |
{ | |
printf("%d",bigmod(5,55,231)); | |
return 0; | |
} | |
int bigmod(int a,int p,int m) | |
{ | |
if(p==0) | |
return 1; | |
if(p%2==0){ | |
int c=bigmod(a,p/2,m); | |
return c*c%m; | |
} | |
else | |
return (a*bigmod(a,p-1,m)) %m; | |
} |
Implement Program 02 :
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
#include<stdio.h> | |
int long long bigmod(int long long a ,int p,int m); | |
int main() | |
{ | |
int long long a; | |
int p,m; | |
printf("%lld ",bigmod(5,55,231)); | |
return 0; | |
} | |
int long long bigmod(int long long a ,int p,int m) | |
{ | |
if(p==0) | |
return 1; | |
if(p%2==0){ // p is even then split it up and mod | |
int c=bigmod(a,p/2,m); | |
return ( (c%m) * (c%m) )%m; | |
} | |
else // p is odd then make it even | |
return ( (a%m)* bigmod(a,p-1,m) ) %m; | |
} |
Download-Pdf From shafaetsplanet.com for more details about BigMod or You can watch the recursion tree it might be helpful.