Cod sursa(job #2845578)

Utilizator IanisBelu Ianis Ianis Data 7 februarie 2022 23:19:36
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <cmath>
 
using namespace std;
 
#ifdef LOCAL
ifstream f("input.txt");
#define g cout
#else
ifstream f("lgput.in");
ofstream g("lgput.out");
#endif
 
const uint64_t MOD = 1999999973;

uint32_t x, y;

uint32_t pow2(uint64_t x, uint64_t n) {
	if (y == 0)
		return 1;
	int y = 1;

	while (n > 1) {
		if (n % 2 == 0)
			n /= 2;
		else {
			y = (uint64_t)x*(uint64_t)y % (uint64_t)MOD;
			n = (n - 1) / 2;
		}
		x = (uint64_t)x*(uint64_t)x % (uint64_t)MOD;
	}

	return (uint64_t)x * (uint64_t)y % MOD;	
}

int main() {
	f >> x >> y;
	g << pow2(x, y);
}