Cod sursa(job #1563756)

Utilizator AetheryonStefan Bereghici Aetheryon Data 6 ianuarie 2016 16:53:04
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
const char* IN = "inversmodular.in";
const char* OUT = "inversmodular.out";

class Math {
    private :
        Math(){}
        ~Math(){}

    public :
        static void euclidExtended(int a,int b,int &x,int &y){
            if (b==0) {
                x = 1;
                y = 0;
                return;
            }
            euclidExtended(b,a%b,x,y);
            int aux = x;
                x = y;
                y = aux - a/b * y;
        }
};

int n,a,b,c,x,y,sol;
int main(void){
    ifstream cin(IN);
    ofstream cout(OUT);
    cin>>a>>b;
    Math::euclidExtended(a,b,x,y);
    x+=(x<0) ? b : 0;
    cout<<x;
    return 0;
}