Cod sursa(job #336726)
| Utilizator | Data | 1 august 2009 12:46:00 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <stdio.h>
#define mod 1999999973
long long int putere(int n,int p)
{
long long int aux;
if (p == 1)
{
return n;
}
if (p == 0)
{
return 1;
}
if (p % 2 == 0)
{
aux = putere(n,p/2);
return ((aux % mod) * (aux % mod)) % mod;
}
aux = putere(n,p/2);
return (((aux % mod)*(aux % mod) % mod) * n) % mod;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int n,p;
scanf("%d%d",&n,&p);
printf("%lld\n",putere(n,p));
return 0;
}
