Cod sursa(job #2026899)

Utilizator calinfloreaCalin Florea calinflorea Data 25 septembrie 2017 12:14:35
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>
#define modulo 1999999973
using namespace std;

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

long long s = 1;
int p;
int n;

void Citire()
{
    fin >> n >> p;
}

void Ridica()
{
    while(p > 0)
    {
        if(p % 2 == 1)
        {
            s = (1LL * s * n) % modulo;
            p--;
        }
        p /= 2;
        n = (1LL * n * n) % modulo;
    }

    fout << s << "\n";
}
int main()
{
    Citire();
    Ridica();
    return 0;
}