Cod sursa(job #2034052)

Utilizator razvanboabesrazvan boabes razvanboabes Data 7 octombrie 2017 13:25:41
Problema Invers modular Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
long long xpow(long long b,long long e,long long mod)
{
    long long ans=1;
    while(e > 0)
    {
        if (e % 2)
            ans=ans*b%mod;
        b = b * b % mod;
        e /= 2;
    }
    return ans;
}
int main()
{
    int a,n,i,prod=1;
    in>>a>>n;
      out<<xpow(a,n-2,n);
    return 0;
}