Pagini recente » Cod sursa (job #2646324) | Profil GeorgianaPurcaru | Cod sursa (job #2231010) | Cod sursa (job #2418224) | Cod sursa (job #1411936)
#include <iostream>
#include <fstream>
static const int mod = 1999999973;
int expSquare(int x, int 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 ;
else if ( n % 2 == 1 ) return (x * expSquare((x*x)%mod,(n-1)/2)%mod)%mod;
}
int main( int argc, char* argv[] )
{
std::ifstream input( "lgput.in" );
std::ofstream output( "lgput.out" );
int N,P;
input >> N >> P;
output << expSquare(N,P) ;
input.close();
output.close();
return 0;
}