Cod sursa(job #1284670)
Utilizator | Data | 6 decembrie 2014 18:40:55 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
long int PutereLogaritmic(int x, int n)
{
long int p = 1 ;
while (n > 0)
{
if (n%2==1)
{
p *= x;
n-- ;
}
x = x * x ;
n = n / 2;
}
return p ;
}
int n,p;
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d%d", &n, &p);
printf("%d",PutereLogaritmic(n,p)% 1999999973);
return 0;
}