Cod sursa(job #178747)
| Utilizator | Data | 15 aprilie 2008 01:10:50 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include<stdio.h>
#define REST 1999999973
typedef long long LL;
LL n,p,sol;
LL functie( LL x )
{
if(x==1) return n % REST;
else
if(x%2==0) { sol=functie(x/2) % REST; return (sol*sol) % REST; }
else return ( (functie(x-1) % REST) * (n % REST) ) % REST;
}
main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld", &n, &p);
printf("%lld\n", functie(p) );
}
