Cod sursa(job #1241301)

Utilizator muresan_bogdanMuresan Bogdan muresan_bogdan Data 13 octombrie 2014 10:29:30
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<iostream>
#include<fstream>
using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

#define MOD 1999999973

int n, p;

long long exp(int a, int b) {

    long long rez = 1;
    while(b > 0) {
        if(b%2) {
            b--;
            rez = (rez * a) % MOD;
        }else {
            a = (a * a) % MOD;
            b /= 2;
        }
    }
    return rez;
}

int main() {
    fin >> n >> p;
    fout << exp(n, p);
    return 0;
}