Cod sursa(job #1386588)
| Utilizator | Data | 13 martie 2015 08:49:19 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#define modulo 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p;
long long lgput(int p)
{
long long aux;
if (p==0) return 1;
else
{
if (p%2==0)
{
aux=lgput(p/2)%modulo;
return ((aux%modulo)*(aux%modulo))%modulo;
}
else return (n*(lgput(p-1))%modulo)%modulo;
}
}
int main ()
{
f>>n>>p;
g<<lgput(p);
return 0;
}
