Advertisement
NgJaBach

Exponentiation

Aug 2nd, 2021 (edited)
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long int ll;
  5. //#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
  6. #define pb push_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define gcd __gcd
  11. #define getl(s) getline(cin, s);
  12. #define setpre(x) fixed << setprecision(x)
  13. #define mset(a) memset(a, 0, sizeof(a))
  14. #define endl '\n'
  15. const int N=100050,M=1000000009;
  16. const ll INF=1e18+7;
  17.  
  18. ll modular(ll x,ll y,ll m){
  19.     ll res=1;
  20.     x%=m;
  21.     if(x==0) return 0;
  22.     while(y>0){
  23.         if(y&1) res=(res*x)%m;
  24.         y/=2;
  25.         x=(x*x)%m;
  26.     }
  27.     return res;
  28. }
  29. ll indian_mul(ll a,ll b){
  30.     if(b==0) return 0;
  31.     ll n=indian_mul(a,b/2);
  32.     if(b%2==0) return (n+n)%M;
  33.     return (n+n+a)%M;
  34. }
  35. int main(){
  36.     ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
  37. //    freopen(".inp","r",stdin);
  38. //    freopen(".out","w",stdout);
  39.     ll a,b,m;
  40.     cin>>a>>b>>m;
  41.     cout<<modular(a,b,m);
  42.     return 0;
  43. }
  44. /*
  45. ==================================+
  46. INPUT:                            |
  47. ------------------------------    |
  48.  
  49. ------------------------------    |
  50. ==================================+
  51. OUTPUT:                           |
  52. ------------------------------    |
  53.  
  54. ------------------------------    |
  55. ==================================+
  56. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement