fork(1) download
  1. /* Code by
  2.   __ __ __
  3.   /\ \__ /\ \ /\ \
  4.   __ _ __\ \ ,_\ \ \ \___ __ ___\ \ \/'\
  5.  /'__`\ /\`'__\ \ \/ \ \ _ `\ /'__`\ /'___\ \ , <
  6. /\ \L\.\_\ \ \/ \ \ \_ \ \ \ \ \/\ \L\.\_/\ \__/\ \ \\`\
  7. \ \__/.\_\\ \_\ \ \__\ \ \_\ \_\ \__/.\_\ \____\\ \_\ \_\
  8.  \/__/\/_/ \/_/ \/__/ _______\/_/\/_/\/__/\/_/\/____/ \/_/\/_/
  9.   /\______\
  10.   \/______/
  11. */
  12.  
  13. #include <bits/stdc++.h>
  14. using namespace std;
  15. #define max(a, b) (a < b? b : a)
  16. #define min(a, b) ((a>b)?b:a)
  17. #define FOR(a,c) for ( int (a)=0; (a)<(c); (a)++)
  18. #define FORL(a,b,c) for ( int (a)=(b); (a)<=(c); (a)++)
  19. #define FORR(a,b,c) for ( int (a)=(b); (a)>=(c); (a)--)
  20. typedef unsigned long long int ll;
  21. typedef vector<int> vi;
  22. typedef pair<int,int> pi;
  23. #define F first
  24. #define S second
  25. #define PB push_back
  26. #define POB pop_back
  27. #define MP make_pair
  28.  
  29. int main() {
  30. ios::sync_with_stdio(0);
  31. cin.tie(0);
  32.  
  33. ll mod[100001]={0};
  34.  
  35. ll T;
  36. cin>>T;
  37. while(T--){
  38. ll A,N,P;
  39. cin>>A>>N>>P;
  40.  
  41. ll amodp = A%P;
  42. mod[0] = amodp;
  43. FOR(i,N){
  44. if(i!=0)
  45. mod[i] = ((mod[i-1]%P)*(amodp%P))%P;
  46. }
  47.  
  48. ll sum = 1;
  49. FOR(i,N)
  50. sum = ((sum%P)*(mod[i]%P))%P;
  51.  
  52. cout<<sum<<endl;
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 15896KB
stdin
Standard input is empty
stdout
Standard output is empty