Cod sursa(job #1141220)
Utilizator | Data | 12 martie 2014 18:36:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const int MOD= 1999999973;
long long putere(long long a, long long p) {
int R= 1;
while( p != 0 ) {
if( p%2 == 1 ) {
R= (R*a) % MOD;
}
p>>= 1;
a= (a*a) % MOD;
}
return R;
}
int main()
{
long long a,b;
in >> a >> b;
out << putere( a, b ) << '\n';
return 0;
}