Cod sursa(job #830401)

Utilizator ion824Ion Ureche ion824 Data 6 decembrie 2012 20:11:05
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include<fstream>
using namespace std;
#define ll long long
int A, N;
 
void invmod(ll &x, ll &y, int a, int b) 
{ 
     if (!b) 
         x = 1, y = 0; 
     else 
     {            
         invmod(x, y, b, a % b);
         ll aux = x;
         x = y;
         y = aux - y * (a / b);
     }
}
 
int main()
{
    ll inv = 0, ins;   
    ifstream fin("inversmodular.in");
    ofstream fout("inversmodular.out");    
    fin>>A>>N;
    invmod(inv, ins, A, N);
    if (inv <= 0)
       inv = N + inv % N;        
    fout<<inv;     
    return 0;
}