Cod sursa(job #2998485)

Utilizator Luka77Anastase Luca George Luka77 Data 9 martie 2023 16:43:19
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(WHATEVER) for(int i = 1; i <= WHATEVER; ++ i)

/// INPUT / OUTPUT
const string problem = "lgput";
ifstream fin("lgput.in");
ofstream fout("lgput.out");

/// GLOBAL VARIABLES
const int NMAX = 1, MOD = 1999999973, INF = 1e9;
int n, p;

/// SOLUTION
inline ll lgput(int nr, int exp)
{
    int x = 1, y = nr;
    while(exp)
    {
        if((exp & 1) == 1)
        {
            x = (x * y) % MOD;
        }
        y*=(y%MOD);
        exp >>= 1;
    }
    return x;
}

/// READING THE INPUT
int main()
{
    ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);

    fin >> n >> p;

    fout << lgput(n, p);
}