Cod sursa(job #2329721)

Utilizator HumikoPostu Alexandru Humiko Data 27 ianuarie 2019 12:55:21
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
//#include "pch.h"
#include <iostream>
#include <fstream>

using namespace std;

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

static const long long MOD = 1999999973;

long long lgput(long long base, long long exp)
{
	long long res = 1;
	
	while (exp)
	{
		if (exp % 2)
		{
			exp--;
			res = (base * res)%MOD;
		}
		else
		{
			exp /= 2;
			base = (base * base)%MOD;
		}
	}

	return res;
}


int main()
{
	ios::sync_with_stdio(false);
	fin.tie(0); fout.tie(0);

	long long n, p;
	fin >> n >> p;
	fout << lgput(n, p) << '\n';
}