Cod sursa(job #2095509)
| Utilizator | Data | 27 decembrie 2017 17:01:47 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#define INFILE "lgput.in"
#define OUTFILE "lgput.out"
using namespace std;
typedef unsigned long long ULL;
ifstream in(INFILE);
ofstream out(OUTFILE);
const int mod=1999999973;
ULL expBySquaring(ULL baza,int exp){
ULL result=1;
while(exp>0){
if(exp%2==1){
result*=baza;
result=result%mod;
}
exp=exp/2;
baza=(baza*baza)%mod;
}
return result;
}
int main()
{
ULL n,p;
in>>n>>p;
out<<expBySquaring(n,p);
return 0;
}
