tungggg

fast exponential

Apr 26th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. set<ll> st;
  7.  
  8. const ll mod=1e9+7;
  9.  
  10. ll  powMod ( ll a, ll b ){
  11.     ll ans =1 ;
  12.     for (ll i =1;i<=b;i++){
  13.         ans*=a;
  14.         ans%=mod;
  15.     }
  16.     return ans ;
  17. }
  18.  
  19. ll solve (ll x , ll n ){
  20.     if ( n==0 ) return 1 ;
  21.     ll last_digit= n%10;
  22.     return  powMod(solve(x,n/10),10) % mod * powMod(x,last_digit) % mod;
  23. }
  24.  
  25. int main(){
  26.     ll x, n;
  27.     cin >> x >> n;
  28.     ll res= solve ( x,n );
  29.     cout << res;
  30.  
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment