Cod sursa(job #2469696)

Utilizator modulopaulModulopaul modulopaul Data 7 octombrie 2019 21:12:18
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>
#define NRSPEC 1999999973
#define ll long long

using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
ll pt(int nr,int exp){
    ll rez=1;
    for(int i=0;(1<<i)<=exp;i++){
        if(((1<<i)&exp)>0)
            rez=(rez*nr)%NRSPEC;
        nr=(nr*nr)%NRSPEC;
    }
    return rez;
}
int main(){
    int nr,exp;
    fin>>nr>>exp;
    fout<<pt(nr,exp);
    return 0;
}