Cod sursa(job #2720980)

Utilizator lucidanescu28Danescu Lucian lucidanescu28 Data 11 martie 2021 14:23:34
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>
#define mod 1999999973
#define ll long long
using namespace std;

ll lgput(ll base, ll exponent){
	  	if(exponent == 0) return 1;
       	if(exponent == 1) return base;

        if(exponent % 2 == 0) return (1LL * lgput(base, exponent / 2) * lgput(base, exponent / 2)) % mod;
        return (1LL *(1LL * base * lgput(base, exponent / 2) % mod) * lgput(base, exponent / 2)) % mod;
}

int main(){
	ifstream fin("lgput.in");
	ofstream fout("lgput.out");
	ll x, pow;

	fin >> x >> pow;
	fout << lgput(x, pow);

	return 0;
}