Cod sursa(job #311257)
Utilizator | Data | 3 mai 2009 10:15:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <fstream>
using namespace std;
#define NUME "lgput"
#define P 1999999973
ifstream fi(NUME".in");
ofstream fo(NUME".out");
int main()
{
long long n, q, rez;
fi >> n >> q;
rez = 1;
for (; q; q >>= 1) {
if (q & 1)
rez = (rez * n) % P;
n = (n*n) % P;
}
fo << rez << endl;
return 0;
}