Cod sursa(job #766779)

Utilizator mi5humihai draghici mi5hu Data 12 iulie 2012 10:00:31
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <stdio.h>
#include <math.h>
#define D 1999999973
using namespace std;

long long int power(long long int b, long long int e) {
     if (e == 1) {
        return b % D;
     }
     long long temp = power(b, e/2);
     if (e % 2 == 0) {
        return ((temp * temp) % D);   
     }
     
     return ((temp * temp * b) % D);         
}

void read_(long long int & b, long long int & e) {
     scanf("%lld%lld", &b, &e);     
}

int main() {
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);
           
    long long int r, b, e;
    
    read_(b, e);    
    r = power(b, e);
    
    printf("%lld", r);
    return 0;
}