Cod sursa(job #1916245)
Utilizator | Data | 9 martie 2017 08:44:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#define M 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int n,p,r;
int main(){
fin>>n>>p;
r=1;
while(p!=0){
if(p%2==0){
n=(n*n)%M;
p/=2;
}
else{
r=(r*n)%M;
p--;
}
}
fout<<r;
return 0;
}