Cod sursa(job #1414343)

Utilizator irimiecIrimie Catalin irimiec Data 2 aprilie 2015 15:39:27
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;

#define     mp              make_pair
#define     fs              first
#define     sc              second
#define     pob             pop_back
#define     pub             push_back
#define     eps             1E-7
#define     sz(a)           a.size()
#define     count_one       __builtin_popcount;
#define     count_onell     __builtin_popcountll;
#define     fastIO          ios_base::sync_with_stdio(false)
#define     PI              (acos(-1.0))
#define     linf            (1LL<<62)//>4e18
#define     inf             (0x7f7f7f7f)//>2e9

#ifndef ONLINE_JUDGE
ifstream fin("lgput.in");
ofstream fout("lgput.out");
#endif

const int MAXN = 100;
const int MOD = 1999999973;
typedef long long ll;

ll lgput(int base, int exp) {
    ll sol = 1;
    for(int k = 0; (1 << k) <= exp; ++k) {
        if( ((1 << k) & exp) > 0 )
            sol = (sol * base) % MOD;

        base = (base * base) % MOD;
    }

    return sol;
}

void read() {
    int n, m;
	fin >> n >> m;
	fout << lgput(n, m) << "\n";
}

int main() {
	read();

    return 0;
}