Cod sursa(job #2753222)
Utilizator | Paul Diac diac_paul | Data | 21 mai 2021 16:54:05 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <stdio.h>
#define MOD 1999999973;
long long x, n;
int putere(int x , int n)
{
int r = 1;
for(int k = 1 ; k <= n ; k <<= 1) {
if((n & k))
r *= x;
x = x * x;
}
return r;
}
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld %lld", &x, &n);
int r = 1;
while (n >= 1) {
if (n % 2) {
r *= x;
}
x = x * x;
n /= 2;
}
printf("%lld\n", r);
return 0;
}