Cod sursa(job #3284867)

Utilizator OnetIoanaOnet Ioana OnetIoana Data 12 martie 2025 11:47:11
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(long long a,long long b,long long &x, long long &y)
{
    if(b==0)
    {
        y=1;
        x=1;
    }
    else
    {
        long long x1,y1;
        euclid(b,a%b,x1,y1);
        x=x1;
        y=x1-a/b*y1;
    }
}
int main()
{
    long long a,b,x,y;
    f>>a>>b;
    euclid(a,b,x,y);
    if(x<0)
    {
        while(x<0)
            x+=b;
    }
g<<x;
    return 0;
}