Cod sursa(job #3237286)

Utilizator popescu_georgePopescu George popescu_george Data 8 iulie 2024 09:08:42
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.36 kb
#include<fstream>
using namespace std;
ifstream F("inversmodular.in");
ofstream G("inversmodular.out");
int a,b,d,x,y;
void A(int a,int b,int *d,int *x,int *y)
{
    if(!b)
        *d=a,*x=1,*y=0;
    else {
        int e,f;
        A(b,a%b,d,&e,&f),*x=f,*y=e-(a/b)*f;
    }
}
int main()
{
    return F>>a>>b,A(a,b,&d,&x,&y),G<<(x<0?b-x%b:x),0;
}