Cod sursa(job #1257851)

Utilizator Stefanel55Buracu Stefan Stefanel55 Data 8 noiembrie 2014 11:49:25
Problema Invers modular Scor 0
Compilator cpp Status done
Runda cls6ichbsim1 Marime 0.41 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ("inversmodular.in");
ofstream out ("inversmodular.out");
int n;
long long pow(int x,int y)
{ if(y==1)
             return x;
  long long val=pow(x,y/2);
  if(y%2==1)
               return val*val%n*x%n;
  return val*val%n;
}
int main()
{
    long long a,n,x;
    in>>a>>n;
    x=pow(a,n-2);
    out<<x%n;
    return 0;
}