Cod sursa(job #2871210)

Utilizator the4Designerthe4Designer the4Designer Data 13 martie 2022 13:35:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <stdio.h>
#include <string.h>

int fast_pow(int base, int exponent, int mod) {
    if (exponent == 0) {
        return 1;
    }

    int result = fast_pow(base, exponent / 2, mod);
    if (exponent % 2 == 0) {
        return (1LL * result * result) % mod;
    }

    return (1LL * base * fast_pow(base, exponent - 1, mod)) % mod;
} 

	
int main() {
	unsigned int n, p;

	freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);
	
	scanf("%d %d", &n, &p);
	
    int mod = 1999999973;
	printf("%d\n", fast_pow(n, p, mod));
}