Cod sursa(job #1474925)

Utilizator SilviuIIon Silviu SilviuI Data 23 august 2015 10:08:27
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stack>
#include <set>
#define nmax 100010
using namespace std;
int a,b,x,y,z,i,j;
void gcd(int a,int b)
{
    if (b==0) { x=1; y=0; } else
    {
        gcd(b,a%b);
        z=x; x=y;
        y=z-(a/b)*y;
    }
}
int main() {
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&b);
gcd(a,b);
while (x<0) x=x+b;
printf("%d",x);
return 0;
}