Cod sursa(job #2362097)

Utilizator GhSamuelGherasim Teodor-Samuel GhSamuel Data 2 martie 2019 21:56:29
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");

long long n, p;

void read()
{
    f >> n >> p;
}

void solve()
{
    long long x = n, y = 1;
    while(p > 1) {
        if (p & 1)
            y = (y * x) % MOD;
        x = (x * x) % MOD;
        p >>= 1;
    }
    g << (x * y) % MOD;
}

int main()
{
    read();
    solve();
    return 0;
}