Cod sursa(job #936553)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 7 aprilie 2013 18:13:52
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
#define MOD 1999999973
using namespace std;
const char iname[] = "lgput.in";
const char oname[] = "lgput.out";
ifstream fin(iname);
ofstream fout(oname);
long long a, N, ANS = 1, x;
int main()
{
	fin >> a >> N;
	for (x = a; N > 0; N /= 2)
	{
		if (N % 2 == 1) ANS = (ANS * x) % MOD;
		x = (x * x) % MOD;
	}
	fout << ANS << '\n';
	return 0;
}