Cod sursa(job #3296863)

Utilizator christalknightChristian Micea christalknight Data 17 mai 2025 23:31:28
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
//https://infoarena.ro/problema/lgput

#include <iostream>
#include <fstream>

using namespace std;

#define MOD 1999999973

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

unsigned long long exponentiate(unsigned long long n, unsigned long long p)  //computes and returns n to the power of p (modulo 1999999973)
{
    if (p == 0)
        return 1;

    if (p % 2) // p is odd
        return (n * exponentiate((n * n) % MOD, (p - 1) / 2)) % MOD;
    else // p is even
        return exponentiate((n * n) % MOD, p / 2) % MOD;
} 

int main(){
    unsigned long long n, p;
    fin >> n >> p;

    fout << exponentiate(n, p);

    fin.close();
    fout.close();

    return 0;
}