Cod sursa(job #658776)
Utilizator | Data | 9 ianuarie 2012 15:40:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
using namespace std;
long long baza, exponent, rez=1, pasi, mod=1999999973;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
fin>>baza>>exponent;
while(exponent)
{
if(exponent%2==0)
{
rez=(rez*baza*baza)%mod;
exponent/=2;
}
else
{
exponent--;
baza=(baza*baza)%mod;
}
}
fout<<rez<<'\n';
fin.close();
fout.close();
return 0;
}