Cod sursa(job #2642769)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 17 august 2020 09:27:20
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>
#define ll long long

using namespace std;

const int VALMOD = 1999999973;

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

int main()
{
    ll n, p, x, sol = 1;
    fin >> n >> p;
    x = n;
    for(; p; p /= 2){
        if(p % 2 == 1){
            sol *= x;
            sol %= VALMOD;
        }
        x *= x;
        x %= VALMOD;
    }
    fout << sol;
    return 0;
}