Cod sursa(job #2650040)
Utilizator | Data | 17 septembrie 2020 11:16:02 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const long long mod = 1999999973;
long long exp(int n, int p)
{
if (p == 0)
return 1;
else
{
if (p % 2 == 0)
return (exp(n, p / 2) * exp(n, p / 2)) % mod;
else
return (n * exp(n, p / 2) * exp(n, p / 2)) % mod;
}
}
int main(void)
{
int n, p;
fin >> n >> p;
fout<< exp(n, p) % mod;
return 0;
}