Cod sursa(job #612600)
| Utilizator | Data | 8 septembrie 2011 22:49:25 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
#DEFINE m 1999999973
void fast_expo(long n, long p)
{
if (p == 0)
return 1;
long res = fast_expo(p / 2) * fast_expo(p / 2);
if (p % 2 != 0)
res *= n;
return res;
}
int main()
{
FILE *f = fopen("lgput.in","rt");
FILE *g = fopen("lgput.out","wt");
long n, p;
fscanf(f, "%ld %ld", &n, &p);
fprintf(g, "%ld", fast_expo(n, p) % m);
return 0;
}