Cod sursa(job #1136074)
| Utilizator | Data | 8 martie 2014 18:53:14 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
int n,p;
long long putere(int p)
{
long long z;
if (p==0) return 1;
if (p%2==0)
{
z=putere(p/2);
return (z*z)%mod;
}
z=n*putere(p-1);
return z%mod;
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<putere(p);
return 0;
}
