fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5. int x,y,m,i,j,res,temp1,temp2,temp3,new_x,ctr;
  6. scanf("%d %d %d",&x,&y,&m);
  7.  
  8. temp1=x%m;
  9. if(temp1 != 0)
  10. {
  11. for(i=1,temp2=1;i<=y;i++)
  12. {
  13. temp2=temp2*temp1;
  14. }
  15. res=temp2%m;
  16. }
  17. else
  18. {
  19. for(new_x=x,ctr=1;new_x<m;new_x=new_x*x)
  20. {
  21. ctr=ctr+1;
  22. }
  23. temp3=new_x%m;
  24. for(j=1,temp2=1;j<=y/ctr;j++)
  25. {
  26. temp2=temp2*temp3;
  27. }
  28. res=temp2%m;
  29. }
  30. printf("%d",res);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 2164KB
stdin
3 10000000 100000000
stdout
-2467071