Cod sursa(job #2345006)

Utilizator Senth30Denis-Florin Cringanu Senth30 Data 15 februarie 2019 19:51:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const ull d = 1999999973;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

ull N, P;

int power(ull x, ull n){
    if(n == 0){
        return 1;
    } else {
        if(n == 1)
            return x % d;
        else {
            if(n % 2 == 0) {
                return power(x * x % d, n / 2) % d;
            } else if(n % 2 == 1) {
                return (x * power(x * x % d, (n - 1) / 2)) % d;
            }
        }
    }
}

int main(){
    fin >> N >> P;
    fout << power(N, P);

    return 0;
}