fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5.  
  6.  
  7. const int M = 1000000007;
  8. const int N = 3e5+9;
  9. const int INF = 2e9+1;
  10. const int LINF = 2000000000000000001;
  11.  
  12.  
  13.  
  14.  
  15. //_ ***************************** START Below *******************************
  16.  
  17.  
  18. int power(int a, int n, int mod=M) {
  19. a %= mod;
  20. int res = 1;
  21. while (n) {
  22. if (n & 1) res = (res*a)%mod;
  23. a = (a*a)%mod;
  24. n >>= 1;
  25. }
  26. return res;
  27. }
  28.  
  29. int binPower(int a, int n, int mod=M){
  30. if(n==0) return 1;
  31.  
  32. int res = binPower(a, n/2)%mod;
  33.  
  34. if(n & 1) return ((res * res)%mod * a)%mod;
  35. return (res * res )%mod;
  36. }
  37.  
  38.  
  39.  
  40. void solve() {
  41.  
  42.  
  43. int a, n;
  44. cin>>a >> n;
  45.  
  46. cout << power(a, n) << " " << binPower(a, n) << endl;
  47.  
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55. int32_t main() {
  56. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  57.  
  58.  
  59. int t = 1;
  60. cin >> t;
  61. while (t--) {
  62. solve();
  63. }
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 5320KB
stdin
3
2 10
3 6
5 5
stdout
1024 1024
729 729
3125 3125