Cod sursa(job #1400864)
| Utilizator | Data | 25 martie 2015 15:03:56 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
#define MOD 1999999973
using namespace std;
int put (int a, int b)
{
if(b==0) return 1;
if(b==1) return a;
long long j=put(a,b/2);
if(b%2==0) return (j*j)%MOD;
else return (((a*j)%MOD)*j)%MOD;
}
int main ()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int n, p;
scanf("%d%d",&n,&p);
printf("%d",put(n,p));
return 0;
}
