Cod sursa(job #2336014)

Utilizator armandpredaPreda Armand armandpreda Data 4 februarie 2019 18:34:02
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <cstdio>
#define CONST 1999999973
using namespace std;

int main()
{
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);
    int n, p, rez = 1;
    scanf("%d%d", &n, &p);
    int mask;
    for (mask = 1; mask <= p; mask <<= 1)
    {
        if (mask & p)
        {
            rez = (1ll * rez * n) % CONST;
        }
        n = (1ll * n * n) % CONST;
    }
    printf("%d\n", rez);
    return 0;
}