Cod sursa(job #3236072)
Utilizator | Data | 25 iunie 2024 22:53:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | c-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <stdio.h>
#define M 1999999973
long long exp_log(long long y, long long x, int n)
{
if (!n)
{
return y;
}
if (n & 1)
{
return log_exp((y * x) % M, (x * x) % M, (n - 1) / 2);
}
else
{
return log_exp(y % M, (x * x) % M, n / 2);
}
}
int main()
{
FILE *filein = fopen("lgput.in", "rb");
FILE *fileout = fopen("lgput.out", "wb");
long long n, p;
fscanf(filein, "%lld", &n);
fscanf(filein, "%lld", &p);
fclose(filein);
fprintf(fileout, "%lld\n", log_exp(1, n, p));
fclose(fileout);
return 0;
}