Cod sursa(job #256074)
Utilizator | Data | 11 februarie 2009 00:36:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
const long c = 1999999973;
int main()
{
ifstream f("lgput.in");
ofstream f2("lgput.out");
long long n,p,rez=1,aux;
f>>n>>p;
aux=n;
for(int i=0; (1<<i)<=p ; i++)
{
if((p>>i)&1) rez = (rez * aux) % c;
aux *= aux % c;
}
f2<<rez%c;
f.close();
f2.close();
return 0;
}