Cod sursa(job #3208773)

Utilizator Darius1414Dobre Darius Adrian Darius1414 Data 29 februarie 2024 22:28:31
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>
using namespace std;
void inv (int a,int b,int &x,int &y)
{
    if (b==0)
    {
        x=1;
        y=0;
        return ;
    }
    int x0,y0;
    inv(b,a%b,x0,y0);
    x=y0;
    y=x0-a/b*y0;
}
int main()
{
    int a,b;
    ifstream f ("inversmodular.in");
    ofstream g ("inversmodular.out");
    f>>a>>b;
    int x,y;
    inv(a,b,x,y);
    while (x<0) x+=b;
    g<<x;
}