Cod sursa(job #2230134)

Utilizator Alex03Runcan Alexandru Alex03 Data 9 august 2018 11:12:18
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.32 kb
#include <bits/stdc.h>
using namespace std;
ifstream fin ("lgput.in"); ofstream fout ("lgput.out");
#define mod 1999999973;

int main ()
{
	long long n, k, p = 1LL;
	fin >> n >> k;
	n %= mod;
	while (k > 1LL)
		if (k&1) p = (p * n) % mod, k--;
		else n = (n * n) % mod, k /= 2;
	fout << (n * p) % mod;
	return 0;
}