Cod sursa(job #1975061)
| Utilizator | Data | 29 aprilie 2017 20:02:03 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
const long long MOD = 1999999973;
long long n, p;
long long power(long long base, long long exp)
{
if(exp == 0)
return 1;
if(exp % 2 == 0)
{
long long x = power(base, exp / 2);
return (x * x) % MOD;
}
else
return (base * power(base, exp - 1)) % MOD;
}
int main()
{
ifstream in("lgput.in");
ofstream out("lgput.out");
in >> n >> p;
out << power(n, p);
in.close();
out.close();
return 0;
}
