Cod sursa(job #1992703)
Utilizator | Postu Alexandru Humiko | Data | 21 iunie 2017 10:19:40 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout("lgput.out");
long long putere(long long n, long long p)
{
long long rezultat=1;
while(p)
{
if (p%2==0)
{
p/=2;
n=(n*n)%1999999973;
}
else
{
--p;
rezultat=(n*rezultat)%1999999973;
}
}
return rezultat;
}
int main()
{
long long n, p;
fin>>n>>p;
fout<<putere(n, p);
}