Cod sursa(job #1007813)
Utilizator | Data | 9 octombrie 2013 19:36:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#define MOD % 1999999973
using namespace std;
ifstream is("lgput.in");
ofstream os("lgput.out");
int n, p, w;
int main()
{
is >> n >> p;
w = 1;
for ( int i = 0; (1 << i) <= p; ++i )
{
if ( (1 << i) & p )
w = ( w * n ) MOD;
n = ( n * n ) MOD;
}
os << w;
is.close();
os.close();
return 0;
}