Cod sursa(job #741603)

Utilizator Victor10Oltean Victor Victor10 Data 26 aprilie 2012 16:23:48
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <cstdio>
#define MOD 1999999973 

long long x;

int pw (long long a) {
	if (a == 0) return 1;
	if (a == 1) return x;
	
	if (a % 2 == 0) return ((pw (a / 2) % MOD) * (pw (a / 2) %MOD));
	return (((pw (a - 1)) % MOD) * x);
}

int main () {
	
	freopen ("lgput.in", "r", stdin);
	freopen ("lgput.out", "w", stdout);
	
	long long a;
	
	scanf ("%lld%lld", &x, &a);
	
	printf ("%d\n", pw (a));
}