al__nasim

Untitled

Dec 9th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int Exmod(int a,int b,int c){
  4. if(b==0)
  5. return 1;
  6. else if(b%2==0){
  7. int d = Exmod(a,b/2,c);
  8. return (d*d)%c;///for (a^b/2%c)*(a^b/2%c)%c here two part are same
  9. ///so you should return (a^b/2%c)^2 then %c.
  10. }
  11. else {
  12. return ((a%c)*Exmod(a,b-1,c))%c;
  13. }
  14.  
  15.  
  16. }
  17. int main()
  18. {
  19. int a,b,c,result;
  20. scanf("%d%d%d",&a,&b,&c);
  21. result = Exmod(a,b,c);
  22. printf("result is : %d\n",result);
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment