Cod sursa(job #2529140)

Utilizator Florinos123Gaina Florin Florinos123 Data 22 ianuarie 2020 23:12:00
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;

ifstream f ("inversmodular.in");
ofstream g ("inversmodular.out");

int a, n;

int ridicarelog (int n, int mod)
{
   int rez = 1, putere = mod - 2;
    while (putere)
    {
        if (putere % 2 == 0)
             rez = (1LL * rez * n) % mod;
        n = (1LL * n * n) % mod;
        putere /= 2;
    }
  return rez;
}

int main()
{
 f >> a >> n;
 g << ridicarelog(a, n);
    return 0;
}