Cod sursa(job #1533734)
Utilizator | Data | 22 noiembrie 2015 21:45:43 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include<stdio.h>
#include<stdlib.h>
int const m = 1999999973;
long long n, p, y;
int main()
{
FILE *f, *g;
f = fopen("lgput.in", "r");
fscanf(f,"%1d%1d", &n, &p);
fclose(f);
g = fopen("lgput.out", "w");
y = 1;
while (p > 1)
{
if (p % 2 == 0)
{
n = (n*n)%m;
p /= 2;
}
else
{
y = (y*n)%m;
n = (n*n)%m;
p = (p - 1) / 2;
}
}
fprintf(g, "%1d", (y*n) % m);
}