Cod sursa(job #2200966)
Utilizator | Data | 2 mai 2018 22:36:36 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void gcd(int a, int b, int &x, int &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
int x0, y0;
gcd(b, a%b, x0, y0);
x=y0;
y=x0-y0*(a/b);
}
int main()
{
int A, N, X, Y;
f>>A>>N;
gcd(A, N, X, Y);
g<<X;
return 0;
}