Cod sursa(job #875899)
| Utilizator | Data | 10 februarie 2013 21:58:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#include <math.h>
#define m 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,p,i,r,a;
long long putere(long long int x,long long y)
{
a=1;
while(p>0)
if(p%2==0)
{
n=(n*n)%m;
p=p/2;
}
else
{
a=(a*n)%m;
p--;
}
return a;
}
int main()
{
f>>n>>p;
g<<putere(n,p);
return 0;
}
