Cod sursa(job #2805846)
Utilizator | Data | 22 noiembrie 2021 02:33:00 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <stdio.h>
#define a 1999999973
using namespace std;
FILE* f, * g;
int main()
{
long long n, p, pp = 1;
f = fopen("lgput.in", "r");
g = fopen("lgput.out", "w");
fscanf(f, "%lld %lld", &n, &p);
while (p != 0)
{
if (p % 2 != 0)
{
pp = pp * n % a;
p--;
}
n = n * n % a;
p = p / 2;
}
fprintf(g, "%lld", pp);
fclose(f);
fclose(g);
return 0;
}