Cod sursa(job #488474)

Utilizator testAccounttestAccount testAccount Data 28 septembrie 2010 22:16:52
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <cstdio>

#define MOD 1999999973

long long unsigned compute(long long unsigned n, long long unsigned p)
{
	if(!p)
		return 1;
	long long unsigned t = compute(n, p>>1);
	if(p & 1)
		return (((t * t) % MOD) * n) % MOD;
	else
		return (t * t) % MOD;
}

int main()
{
	freopen("lgput.in", "r", stdin);
	freopen("lgput.out", "w", stdout);

	long long unsigned n, p;
	scanf("%llu %llu", &n, &p);
	printf("%llu", compute(n, p));

	fclose(stdin);
	fclose(stdout);
	return 0;
}