Cod sursa(job #1959283)

Utilizator shantih1Alex S Hill shantih1 Data 9 aprilie 2017 12:26:43
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.35 kb
#include <iostream>
#include <fstream>

using namespace std;

long long a, b, ans, mod = 1999999973;

int main () {
	
	ifstream fin("lgput.in");
	ofstream fout("lgput.out");
	
	fin >> a >> b;
	ans = 1;
	while (b != 0)
	{
		if (b % 2 == 0)
		{
			b /= 2;
			a = (a*a) % mod;
		}
		
		else
		{
			ans = (ans*a) % mod;
			b--;
		}
	}
	
	fout << ans;
	return 0;
}