Cod sursa(job #3298388)

Utilizator Bolbotina_David-AndreiBolbotina David-Andrei Bolbotina_David-Andrei Data 29 mai 2025 10:17:51
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");

long long exp_log(short x, long long n, long long mod) {
    if (n == 0)
        return 1;
    long long p = 1;
    x = x % mod;
    while (n > 0) {
        if (n % 2)
            p = (p * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return p;
}


int main() {
    short n;
	long long p;
	fin>>n>>p;
	long long mod = 1999999973;
	long long s = exp_log(n, p, mod);
	fout<<s;

	return 0;
}