Cod sursa(job #1734180)
Utilizator | Data | 26 iulie 2016 18:37:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 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;
s=(n*n*2)%x;
}
else
{
p--;
s=(s*n)%x;
}
}
out<<s;
return 0;
}