Cod sursa(job #1188256)

Utilizator romircea2010FMI Trifan Mircea Mihai romircea2010 Data 19 mai 2014 10:29:49
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

const long long MOD = 1999999973LL;
long long N, P;

inline long long PutLog(long long baza, long long exp)
{
    long long put = 1LL;
    while (exp)
    {
        if (exp & 1)
        {
            --exp;
            put = 1LL * put * baza % MOD;
        }
        else
        {
            baza = 1LL * baza * baza % MOD;
            exp /= 2;
        }
    }
    return put;
}

int main()
{
    ifstream f("lgput.in");
    f >> N >> P;
    f.close();
    ofstream g("lgput.out");
    g << PutLog(N, P) << "\n";
    g.close();
    return 0;
}