Cod sursa(job #2330038)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 27 ianuarie 2019 19:29:54
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 kb
/*
ID: gabriel100
LANG: C++
TASK:
*/
#include <cstdio>
#include <algorithm>
//#include <time.h>
#include <queue>
#include <cmath>
#include <stack>
#include <fstream>
#include <bitset>
#include <set>
#include <map>

#define nl '\n'
#define F first
#define S second
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define eb(x) emplace_back(x)
#define ull unsigned long long
#define ll long long
#define ProblemName "lgput"
#define LocalName "data"
#ifdef INFOARENA
#define Filename ProblemName
#else
#define Filename LocalName
#endif
#define Input Filename".in"
#define Output Filename".out"
using namespace std;
ifstream cin(Input);
ofstream cout(Output);

template<class a, class type>
void print(a v, type t) {
    for_each(all(v), [](type x) { cout << x << ' '; });
    cout << nl;
}

const int M = 1999999973
int power(int n,int p){
    int r = 1;
    while(p){
        if(p%2)
            r = (1LL*r*n)%M;
        n = (1LL*n*n)%M;
        p/=2;
    }
    return r;
}
int n,p;
int main() {
    ios_base::sync_with_stdio(false);
    //clock_t tStart = clock();
    cin >> n >> p;
    cout << power(n,p);
    cout.close();
    //printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}