Cod sursa(job #1725221)

Utilizator Mihaibv13Mihai Stoian Mihaibv13 Data 5 iulie 2016 11:17:16
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cstdio>
using namespace std;

int main()
{
    FILE *f=fopen("inversmodular.in","r"),*g=fopen("inversmodular.out","w");
    int n,a[100],b[100],q[100],k,x0,y0,x1,y1,i,c=1;


        k=1;
        fscanf(f,"%d%d",&a[1],&b[1]);
        while(b[k])
        {
            q[k]=a[k]/b[k];
            ++k;
            a[k]=b[k-1];
            b[k]=a[k-1]%b[k-1];
        }
        if(c%a[k])fprintf(g,"0 0\n");
        else
        {
            x0=c/a[k];
            y0=0;
            k--;
            while(k)
            {
                x1=y0;
                y1=x0-q[k]*y0;
                k--;
                x0=x1;
                y0=y1;
            }
            fprintf(g,"%d",x0);
        }

    return 0;
}