Cod sursa(job #3284717)

Utilizator crina2120Arnautu Cristina-Crina crina2120 Data 12 martie 2025 09:24:19
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>
#define MOD 1999999973
using namespace std;

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

int a, b;

int Expolog(int a, int n, int mod)
{
    int p = 1;
    while (n > 0)
    {
        if (n % 2 == 1) p = 1LL * p * a % mod;
        a =1LL * a * a % mod;
        n /= 2;
    }
    return p;
}

int main()
{
    fin >> a >> b;
    fout << Expolog(a, b, MOD);
    return 0;
}
//0 1 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 21 22 24 25 26 27 29 30 34 35 36 42 44 45 47 48 51 54 56 57 58