Cod sursa(job #642822)

Utilizator bmaticanBogdan-Alexandru Matican bmatican Data 2 decembrie 2011 12:49:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <cstdio>
#include <list>

using namespace std;

int n;
int p;
const int MOD = 1999999973;

void solve() {
  scanf("%d %d", &n, &p);
  // 10010
  int temp = p;
  long long result = 1;
  long long x = n;
  while (temp) {
    if (temp % 2 != 0) {
      result = (result * x) % MOD;
    }  
    x = (x * x) % MOD;
    temp /= 2;
  }
  printf("%ld\n", result);
}

int main() {
  freopen("lgput.in", "r", stdin);
  freopen("lgput.out", "w", stdout);

  solve();
  return 0;
}