Cod sursa(job #672904)
| Utilizator | Data | 3 februarie 2012 13:43:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
#include <cstdlib>
#define MODULO 1999999973
using namespace std;
typedef unsigned int uint;
inline uint power( uint x, uint n )
{
uint r;
for( r=1; n; n>>=1 )
{
if( n&1 )
{
r=(1LL*r*x)%MODULO;
--n;
}
x=(1LL*x*x)%MODULO;
}
return r;
}
int main()
{
uint x, n;
ifstream in( "lgput.in" );
ofstream out( "lgput.out" );
in>>x>>n;
out<<power( x, n )<<'\n';
return EXIT_SUCCESS;
}
