Cod sursa(job #1450350)
Utilizator | Data | 12 iunie 2015 20:40:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int MOD = 1999999973;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
long long n,p;
f>>n>>p;
if(p == 0){
g<<1;
return 0;
}
long long rez=1;
while(p){
if(p % 2 == 0){
n= n *n % MOD;
p/=2;
}else{
rez=rez *n % MOD;
p--;
}
}
g<< rez<<endl;
return 0;
}