Cod sursa(job #895980)
Utilizator | Data | 27 februarie 2013 13:19:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long a,p,r;
int main()
{
in>>a>>p;
r=1;
while(p!=0){
if(p%2==0){
a=(a*a)%1999999973;
p=p/2;}
else{
r=(r*a)%1999999973;
a=(a*a)%1999999973;
p=p/2;}}
out<<r;