Cod sursa(job #3167585)

Utilizator InformaticianInDevenire1Munteanu Mihnea Gabriel InformaticianInDevenire1 Data 10 noiembrie 2023 20:57:05
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    long long n,p,modulo = 1999999973,ans = 1;
    fin >> n >> p;
    while (p>0){
        if (p%2==0){
            n = n * n;
            p = p / 2;
        }else{
            p -= 1;
            ans *= n;
            ans = ans % modulo;
            p = p / 2;
            n = n * n;
        }
    }
    fout << ans;
    return 0;
}