Cod sursa(job #457348)

Utilizator GulyanAlexandru Gulyan Data 18 mai 2010 23:27:53
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator c Status done
Runda Arhiva educationala Marime 0.39 kb
#include <stdio.h>

#define c 1999999973

unsigned put(unsigned n, unsigned p) {
  if(p == 0)
    return 1;
  unsigned x = put(n, p/2);
  x = (x * x ) % c;
  if(p%2)
    x = x * n;
  return x % c;
}

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

  unsigned int n, p;
  scanf("%u %u", &n, &p);
  printf("%u\n", put(n, p));

  fclose(stdout);

  return 0;
}