Pagini recente » Clasament ezpz01 | Cod sursa (job #2524257) | Cod sursa (job #2342184) | Cod sursa (job #2436861) | Cod sursa (job #1411942)
#include <iostream>
#include <fstream>
static const int mod = 1999999973;
long long expSquare(long long x, long long n)
{
if ( n < 0 ) return 1;
else if ( n == 0 ) return 1;
else if ( n == 1 ) return x % mod;
else if ( n % 2 == 0 ) return expSquare((x*x)%mod ,(n/2)%mod)%mod ;
else if ( n % 2 == 1 ) return (x * (expSquare((x*x)%mod,(n/2)%mod))%mod)%mod;
}
int main( int argc, char* argv[] )
{
std::ifstream input( "lgput.in" );
std::ofstream output( "lgput.out" );
long long N,P;
input >> N >> P;
output << expSquare(N,P) ;
input.close();
output.close();
return 0;
}