Cod sursa(job #161740)
Utilizator | Emanuel Cinca c_e_manu | Data | 18 martie 2008 19:10:12 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
//#include<iostream.h>
//#include<conio.h>
#include<fstream.h>
long pow(long x, long n)
{ long long m=1999999973;
long result = 1;
while ( n ) {
if ( n & 1 ) {
result = result * x;
n = n-1;
}
x =(x*x) %m;
n = (n/2)%m;
}
return result;
}
int main()
{ ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p;
//clrscr();
fin>>n>>p;
fout<<pow(n,p);
//getch();
return 0;
}