Cod sursa(job #2629191)

Utilizator RaduQQTCucuta Radu RaduQQT Data 19 iunie 2020 14:16:52
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>




#define ll long long 



ll ridLaPutere(ll n, ll p)
{
	n %= 1999999973;
	if (p == 0)
		return 1;
	if (p == 1)
		return n;
	if (p % 2 == 0)
		return ridLaPutere(n * n, p / 2);
	else
		return (n * ridLaPutere(n * n, (p - 1) / 2))% 1999999973;
	
}

int main()
{
	ll n, p;
	freopen("lgput.in", "r", stdin);
	freopen("lgput.out", "w", stdout);
	scanf("%lld%lld", &n, &p);

	printf("%lld", ridLaPutere(n, p));
}