Cod sursa(job #558174)
Utilizator | Data | 17 martie 2011 09:37:38 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.3 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int n, p, rez, px;
bool r;
int main()
{
fin>>n>>p;
px=n;
while (p)
{
r=p%2;
if (r!=0)
rez=rez+px%1999999973;
p/=2;
px=(px*px)%1999999973;
}
fout<<rez;
return 0;
}