al__nasim

p^q mod c = ?

Apr 2nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. //p^q mod c = ?
  2. #include<stdio.h>
  3. int main()
  4. {
  5. int p,q,c,t;
  6. scanf("%d",&t);
  7. for(int i = 0; i<t; i++)
  8. {
  9. scanf("%d %d %d", &p,&q,&c);
  10. }
  11. int temp = 1;
  12. for(int j = 1; j<=q; j++)
  13. {
  14. temp *= p;
  15. }
  16. int res = temp % c;
  17. printf("Result = %d\n",res);
  18. for(int j= 1; j<=q; j++)
  19. {
  20. temp *= p;
  21. temp %= c;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment