Cod sursa(job #1357181)

Utilizator bilbor987Bogdan Pocol bilbor987 Data 23 februarie 2015 20:04:34
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#define MOD 1999999973
using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

long long N,P;
long long Sol=1;

void Read()
{
fin>>N>>P;
}

void Solve()
{
	while(P)
	{
	if(P%2==1)
		Sol = (Sol * N) % MOD;
	N = (N * N)%MOD;
	P = P/2;
	}

	/*for(int i = 0; i<32; i++)
		{
			if(P & (1<<i))
				{
					Sol = (Sol * N) % MOD;
				}
			N = (N * N)% MOD;
		}
*/
}

void Print()
{
fout<<Sol<<"\n";
}

int main()
{
    Read();
    Solve();
    Print();
    return 0;
}