Cod sursa(job #3131605)

Utilizator yungxristfaur cristian yungxrist Data 20 mai 2023 18:05:58
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int recPow(unsigned int n, unsigned int p)
{
    if (p < 0)
        return recPow(1 / n, -p);
    if (p == 0)
        return 1;
    if (p % 2 == 0)
        return recPow(n * n, p / 2);
    if (p % 2 == 1)
        return n * recPow(n * n, (p - 1) / 2);
}
int main()
{
    float n;
    int p;
    int pow;
    int x=1999999973;
    in >> n >> p;
    pow = recPow(n, p);
    out << pow%x;
    return 0;
}