Cod sursa(job #1803308)

Utilizator woogiefanBogdan Stanciu woogiefan Data 11 noiembrie 2016 11:37:39
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#define mod 1999999973;

using namespace std;

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

long long lgpow(long long base , long long power)
{
	long long yBase = 1;
	while (power > 1){
		if(power % 2 == 0){
			base *= base;
			power /= 2;
			base %= mod;
		}
		else{
			yBase *= base;
			yBase %= mod;
			base *= base;
			power = (power - 1) / 2;
			base %= mod;
		}
	}
	long long Answer = (base * yBase) % mod;
	return Answer;
}

int main() {
	long long n , putere;
	//cin >> n >> putere;
	fin >> n >> putere;
	
	//cout << lgpow (n , putere);
	fout << lgpow(n , putere);
	return 0;
}