Cod sursa(job #256077)
| Utilizator | Data | 11 februarie 2009 00:43:00 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| 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*aux) % c;
}
f2<<rez;
f.close();
f2.close();
return 0;
}
