Cod sursa(job #3357855)

Utilizator octavP18Podan Octvavin octavP18 Data 13 iunie 2026 18:04:53
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>

#include <fstream>

#include <map>

#include <algorithm>

#include <vector>

#include <stack>

using namespace std;

#define all(x) x.begin(), x.end()
#define fs first
#define sc second

using namespace std;

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

const int mod = 1999999973;

long long power = 1;
long long rez = 1;
int n, p;

int main() {

	fin >> n >> p;
	power = n;
	for (int bit = 0; (1 << bit) <= p; ++bit) {
		if (p & (1 << bit)) {
			rez = 1LL * rez * power % mod;
		}
		power = 1LL * power * power % mod;
	}
	fout << rez;
}