Cod sursa(job #2050113)

Utilizator trifangrobertRobert Trifan trifangrobert Data 27 octombrie 2017 22:43:08
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
#define MOD 1999999973

using namespace std;

long long lgput(long long base, long long exp)
{
    long long rez = 1;
    while(exp > 0)
    {
        if (exp & 1)
        {
            rez = (1LL * rez * base) % MOD;
            --exp;
        }
        base = (1LL * base * base) % MOD;
        exp >>= 1;
    }
    return rez;
}

int main()
{
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    int n, m;
    fin >> n >> m;
    fout << lgput(n, m);
    fin.close();
    fout.close();
    return 0;
}