Cod sursa(job #1475470)

Utilizator salam1Florin Salam salam1 Data 24 august 2015 09:01:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <cstdio>
const int MOD = 1999999973;
typedef long long ll;
ll n, exp;

ll lgput(ll base, ll exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) {
      res = (res * base) % MOD;
    }
    base = (base * base) % MOD;
    exp >>= 1;
  }
  
  return res;
}

int main() {
  freopen("lgput.in", "r", stdin);
  freopen("lgput.out", "w", stdout);
  
  scanf("%lld%lld", &n, &exp);
  printf("%lld\n", lgput(n, exp));
  return 0;
}