Cod sursa(job #2865531)

Utilizator radu.Radu Cristi radu. Data 8 martie 2022 21:40:24
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long N, P;
int main()
{
    long long ans = 1;
    fin >> N >> P;
    while (P) {

        if (P & 1) {
            ans = ans * N;
            ans = ans % MOD;
            --P;
        }
        else {
            N = N * N;
            N = N % MOD;
            P = (P >> 1);
        }
    }
    fout << ans << "\n";
    return 0;
}