Cod sursa(job #561212)
| Utilizator | Data | 19 martie 2011 07:32:53 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 kb |
#include "stdio.h"
FILE *f=fopen("lgput.in","r");
FILE *g=fopen("lgput.out","w");
long x=1999999973;
int n;
long hatvany(int b);
int main()
{
int p;
fscanf(f,"%d%d",&n,&p);
long meg=hatvany(p);
fprintf(g,"%ld",meg%x);
fclose(f);
fclose(g);
return 0;
}
long hatvany(int b)
{
if(b==1)return n;
long c=hatvany(b/2);
if(b%2) return (n*c*c)%x;
return (c*c)%x;
}