Cod sursa(job #1970464)

Utilizator bogdan10bosBogdan Sitaru bogdan10bos Data 19 aprilie 2017 13:04:36
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;

#define FILE_IO

const int mod = 1999999973;

int power(int x, int y)
{
    if(y == 0)  return 1;
    if(y == 1)  return x;
    int ans = power( (1LL * x * x) % mod, y / 2 );
    if(y & 1)   ans = (1LL * ans * x) % mod;
    return ans;
}

int main()
{
    #ifdef FILE_IO
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);
    #endif

    int N, M;
    cin >> N >> M;
    cout << power(N, M);

    return 0;
}