Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<stdio.h>
  4. using namespace std;
  5.  
  6.  
  7. unsigned long long ptg(unsigned long long a, unsigned long long n, unsigned long long m)
  8. {
  9.  
  10. unsigned long long c;
  11.  
  12. if (n==0)
  13. { return 1;}
  14.  
  15. c = ptg(a, n/2, m);
  16.  
  17. if (n%2==0)
  18. {
  19. return (c*c)%m;
  20. }
  21. else return (c*c*a)%m;
  22.  
  23.  
  24. }
  25.  
  26.  
  27.  
  28.  
  29. int main()
  30. {
  31. unsigned long long n;
  32. unsigned long long a;
  33. unsigned long long x;
  34. unsigned long long m;
  35. unsigned long long wynik[1000000];
  36.  
  37. scanf("%llu", &x);
  38.  
  39. for (int i=0; i<x; i++)
  40. {
  41. scanf("%llu",&a);
  42. scanf("%llu",&n);
  43. scanf("%llu",&m);
  44.  
  45. wynik[i]=(ptg(a, n, m));
  46.  
  47. }
  48.  
  49. for (int i=0; i<x; i++)
  50. {
  51.  
  52. //cout << wynik[0+i] << endl;
  53.  
  54. printf ("%llu", wynik[i]);
  55. printf ("\n");
  56. }
  57.  
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement