Cod sursa(job #1734181)
Utilizator | Data | 26 iulie 2016 18:38:10 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{
unsigned long long n,p,x=1999999973,s=1,i;
in>>n>>p;
while (p)
{
if (p%2==0)
{
p=p/2;
n=(n*n)%x;
}
else
{
p--;
s=(s*n)%x;
}
}
out<<s;
return 0;
}