Cod sursa(job #3207124)

Utilizator Hotea_MihaelMihael Hotea Hotea_Mihael Data 25 februarie 2024 11:59:26
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>

#define mod 1999999973
using namespace std;

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

int main()
{
    long long a, b;
    fin >> a >> b;

    long long p = a;
    long long ans = 1;
    long long exp = 1;
    while(exp <= b){
        if(exp & b){
            ans *= p;
            ans %= mod;
        }
        p = (p % mod * p % mod) % mod;
        p %= mod;
        exp *= 2;
    }

    fout << ans << '\n';
    return 0;
}