Cod sursa(job #3169796)
Utilizator | Data | 16 noiembrie 2023 00:02:04 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#define MOD 1999999973
#define ull unsigned long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
ull N,P;
ull exp(ull N, ull P) {
if (P==0) return 1LL;
else if (P%2==0) return (exp(N*N, P/2))%MOD;
else return (N*exp(N*N, (P-1)/2))%MOD;
}
int main()
{
f >> N >> P;
g << exp(N,P)%MOD;
return 0;
}