Cod sursa(job #2465968)
| Utilizator | Data | 1 octombrie 2019 09:37:56 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
#define MOD 1999999973
#define LLI long long int
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
LLI n, p;
LLI logPow(LLI n, LLI p)
{
if(p < 0)
return 1LL * logPow(1/n, -p) % MOD;
else if(p == 0)
return 1;
else if(p == 1)
return n;
else if(p % 2)
return 1LL * logPow(n * n, p * (p - 1) / 2) % MOD;
else
return 1LL * logPow(n * n, p / 2) % MOD;
}
int main()
{
fin >> n >> p;
fout << logPow(n, p);
return 0;
}
