Cod sursa(job #2707010)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 16 februarie 2021 12:22:28
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>

using namespace std;

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

const long long int mod = 1999999973;
int main()
{
    long long int n, p;
    fin >> n >> p;

    long long ans = 1;

    while(p > 0)
    {
        if(p % 2 == 1)
        {
            ans *= n;
        }
        n = (n * n) % mod;
        p /= 2;
        ans %= mod;
    }
    fout << ans;
    return 0;
}