Cod sursa(job #284811)

Utilizator crawlerPuni Andrei Paul crawler Data 21 martie 2009 23:17:58
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <stdio.h>

#define ll long long

void ee(ll a,ll b,ll &x,ll &y)
{
    if (b == 0)    
    {
       x = 1;
       y = 0;
    }
       else
    {
        ll x0,y0;
        ee(b,a%b,x0,y0);
        x = y0;
        y = x0 - (a/b)*y0;
    }
}

int main()
{
    freopen("inversmodular.in","r",stdin);
    freopen("inversmodular.out","w",stdout);
    
    ll a,n,sol,x;
    
    scanf("%lld%lld", &a,&n);
    
    ee(a,n,sol,x);
    
    while (sol < 0) 
          sol += n;
    printf("%lld\n", sol);
        
    return 0;    
}