Cod sursa(job #2698783)

Utilizator pielevladutPiele Vladut Stefan pielevladut Data 22 ianuarie 2021 23:58:09
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>
#define int unsigned long long
#define MOD 1999999973
using namespace std;

int n, sol, submultimi;
int x, pare, impare;
int factorial[1000001];

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

int lgput(int base, int exp)
{
    int aux = base, ans = 1;
    for(int i = 1; i <= exp; i *= 2)
    {
        if(i & exp)
        {
            ans = ans * aux;
            aux %= MOD;
        }
        aux = aux * aux;
        aux %= MOD;
    }
    return ans;
}

void precalculare()
{
    factorial[0] = 1;
    for(int i = 1; i <= 1000000; i ++)
    {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= MOD;
    }
}

int combinari(int n, int k)
{
    return (((factorial[n] * lgput(factorial[k], MOD - 2)) % MOD) * lgput(factorial[n-k], MOD - 2)) % MOD;
}

int32_t main()
{
    int a, b;
    fin >> a >> b;
    fout << lgput(a,b);
}