Cod sursa(job #2437673)

Utilizator ShayTeodor Matei Shay Data 9 iulie 2019 23:13:03
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <stdio.h>

#define mod 1999999973
#define lld long long

lld power(lld x, lld y) {
	lld res = 1;
	x = x % mod;

	while (y) {
		if (y & 1) {
			res = (res * x) % mod;
		}

		y >>= 1;
		x = (x * x) % mod;
	}

	return res;
}

int main() {
	freopen("lgput.in", "r", stdin);
	freopen("lgput.out", "w", stdout);
	lld x, p;
	scanf("%lld%lld", &x, &p);
	printf("%lld\n", power(x, p));
	return 0;
}