Cod sursa(job #1800483)
Utilizator | Data | 7 noiembrie 2016 20:06:50 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout("lgput.out");
long long sol,n,p;
int main(){
fin>>n>>p;
sol=1;
while(p>1){
if(p%2==0){
n=(n%1999999973)*(n%1999999973);
p/=2;
}
else{
sol*=n;
sol%=1999999973;
n=(n%1999999973)*(n%1999999973);
p/=2;
}
}
fout<<(n*sol)%1999999973;
return 0;
}