Cod sursa(job #3294358)
| Utilizator | Data | 21 aprilie 2025 23:08:39 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.37 kb |
#include <stdio.h>
#define nmax 1999999973
long long putere(long long A, long long n)
{
long long P = 1;
while(n)
{
if(n%2 == 1)
P = (P*A);
A = (A*A);
n = (n/2);
}
return P%nmax;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
long long n, p;
scanf("%lld%lld", &n, &p);
long long put = putere(n, p);
printf("%lld", put);
}