Cod sursa(job #2151393)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 4 martie 2018 13:50:21
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <cstdio>
using namespace std;
 
typedef long long LL;
 
const int MOD = 1999999973;
 
LL logPow(LL x, LL p) {
	LL ans = 1;
	while (p) {
		if ((p >>= 1) & 1)
			ans = (ans * x) % MOD;
		x = (x * x) % MOD;  
	}
	return ans;
}
 
int main()
{
	freopen("lgput.in", "r", stdin);
	freopen("lgput.out", "w", stdout);
	LL a, b;
	scanf("%lld %lld ", &a, &b);
	printf("%lld\n", logPow(a % MOD, b));
	return 0;
}