Cod sursa(job #3298222)
| Utilizator | Data | 28 mai 2025 14:13:36 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <stdio.h>
#define PRIM 1999999973
unsigned long long fast_exp(unsigned long long N, unsigned long long P)
{
if(P==0) return 1;
else if(P%2) return (N*fast_exp((N*N)%PRIM, P/2)%PRIM)%PRIM;
else return fast_exp((N*N)%PRIM, P/2)%PRIM;
}
int main()
{
unsigned long long N, P;
FILE* fis;
fis = fopen("lgput.in", "r");
fscanf(fis, "%llu %llu", &N, &P);
fclose(fis);
fis = fopen("lgput.out", "w");
fprintf(fis, "%llu", fast_exp(N, P));
fclose(fis);
return 0;
}
