Cod sursa(job #1070071)

Utilizator robertstrecheStreche Robert robertstreche Data 30 decembrie 2013 22:39:01
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include<fstream>
using namespace std;

const int mod = 1999999973;

int main() {
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    long long n, p, aux = 1;
    fin >> n >> p;
    while(p) {
        if(p % 2 == 1) {
            aux *= n;
            aux %= mod;
        }
        n *= n;
        n %= mod;
        p /= 2;
    }
    fout << aux;
    return 0;
}