Cod sursa(job #1551176)

Utilizator BaweeLazar Vlad Bawee Data 15 decembrie 2015 11:34:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

unsigned long long n,p = 1,x;
const int MOD = 1999999973;

int main()
{
    f >> x >> n;

    while(n)
    {
        if(n % 2 == 0)
        {
            x = (x * x) % MOD;
            n /= 2;
        }
        else
        {
            p = (p * x) % MOD;
            n--;
        }
    }

    g << p;

    return 0;
}