Cod sursa(job #1923133)
Utilizator | Data | 10 martie 2017 20:57:10 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long n, p;
int power(long long n, long long p)
{
int x = 1;
while(p)
{
if (p % 2)
{
x *= n;
p--;
}
n *= n;
p /= 2;
}
return x;
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f >> n >> p;
f.close();
g<<power(n, p)% 1999999973 <<"\n";
g.close();
return 0;
}