Cod sursa(job #490661)
Utilizator | Data | 7 octombrie 2010 12:27:31 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
# include <fstream>
using namespace std;
long long N, P, i, a, DEF = 1999999973, SOL = 1;
int main (){
ifstream f ("lgput.in");
f >> N >> P;
a = N;
for (i = 0; (1 << i) <= P; ++i){
if ( ( (1 << i) & P) )
SOL = ( SOL * a % DEF );
a = ( a * a ) % DEF;
}
ofstream g ("lgput.out");
g << SOL << '\n';
g . close ();
return 0;
}