Cod sursa(job #2581097)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 14 martie 2020 15:45:12
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>
#define MOD 1999999973
using namespace std;

long long ridicare(long long a, long long b)
{
    long long c = 1;

    while(b)
    {
        if(b % 2)c = (c * a) % MOD;

        a = (a * a) % MOD;
        b >>= 1;
    }

    return c;
}

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

    ios::sync_with_stdio(false);
    fin.tie(0);
    fout.tie(0);
    srand(time(NULL));

    long long n, p;

    fin >> n >> p;

    fout << ridicare(n, p);

    fin.close();
    fout.close();

    return 0;
}