Cod sursa(job #2689766)

Utilizator CozehNita Horia Teodor Cozeh Data 22 decembrie 2020 02:06:49
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll powlg(ll x, ll b, ll mod) {
	x %= mod;
	if(b < 0) return powlg(1 / x, -b, mod);
	else if(b == 0) return 1;
	else if(b == 1) return x;
	else if(b%2 == 0) return (powlg(x * x, b>>1, mod)) % mod;
	else if(b%2 == 1) return (x * powlg(x * x, (b-1)>>1, mod)) % mod;
}

ifstream fin("lgput.in");
ofstream fout("lgput.out");

int main(){
	ll x,y;
	fin>>x>>y;
	x = powlg(x, y, 1999999973) % 1999999973;
	fout<<x;
}