Cod sursa(job #3251724)
Utilizator | Data | 26 octombrie 2024 17:01:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int pow(int x, int n)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return pow(x*x, n/2);
else
return x * pow(x*x, (n-1)/2);
}
int main()
{
int n, p;
in >> n >> p;
out << pow(n, p) % 1999999973;
return 0;
}