Cod sursa(job #1445672)

Utilizator mouse_wirelessMouse Wireless mouse_wireless Data 30 mai 2015 18:41:19
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <cstdio>
#include <cassert>
#include <algorithm>
#define _submit
#ifdef _submit
#define InFile "lgput.in"
#define OutFile "lgput.out"
#else
#define InFile "fis.in"
#define OutFile "fis.out"
#endif

typedef unsigned long long ULL;

#define MODNR 1999999973

int qpow(int x, int p) {
	if (p == 0)
		return 1;
	else if (p == 1)
		return x;
	if (p % 2 == 0) {
		int aux = qpow(x, p / 2);
		ULL tmp = (ULL(aux) * ULL(aux)) % MODNR;
		return int(tmp);
	}
	int aux = qpow(x, (p - 1) / 2);
	ULL tmp = (ULL(aux) * ULL(aux)) % MODNR;
	tmp = (tmp * ULL(x)) % MODNR;
	return int(tmp);
}

int main() {
	assert(freopen(InFile, "r", stdin));
	assert(freopen(OutFile, "w", stdout));
	int N, p;
	scanf("%d%d", &N, &p);
	printf("%d\n", qpow(N, p));
	return 0;
}