Cod sursa(job #1069466)

Utilizator IeewIordache Bogdan Ieew Data 30 decembrie 2013 02:00:22
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>

using namespace std;

#define DEBUG false

const int divisisor = 1999999973;

#if DEBUG
#include <iostream>
#define INFILE "/Users/biordach/Documents/Xcode Projects/training/training/lgput.in"
#define __OUT cout
#else
#define INFILE "lgput.in"
#define OUTFILE "lgput.out"
ofstream __OUT(OUTFILE);
#endif

long long base, exp, solution = 1;

void readInput();
void solve();
void printOutput();

int main(int argc, const char * argv[])
{
    readInput();
    solve();
    printOutput();

#if DEBUG == false
    __OUT.close();
#endif
    
    return 0;
}

void readInput(){
    ifstream in(INFILE);
    in>>base>>exp;
}

void solve(){
    long long product = base;
    while (exp) {
        if(exp % 2) {
            solution *= product;
            solution %= divisisor;
        }
        product *= product;
        product %= divisisor;
        exp /= 2;
    }
}

void printOutput(){
    __OUT<<solution<<'\n';
}