Cod sursa(job #2605806)

Utilizator drknss_Hehe hehe drknss_ Data 25 aprilie 2020 20:30:22
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
//const ll mod = 1999999973;
const int N = 2e5 + 11;

int a,b;

int gcd(int a,int b,int &x, int &y){

    if(!b){
        x = 1;
        y = 0;
        return b;
    }

    int x0,y0,d;

    d = gcd(b, a%b, x0, y0);

    x = y0;
    y = x0 - y0*(a/b);

    return d;
}


int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");

    cin >> a >> b;

    int x,y;
    int dd  = gcd(a,b,x,y);

    while(x<0)x+=b;

    rc(x);


return 0;
}