Cod sursa(job #1748767)
Utilizator | Data | 26 august 2016 19:52:23 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<iostream>
#include<fstream>
using namespace std;
void functie(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else{
long long x0,y0;
functie(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long a,n,x,y;
f>>a>>n;
functie(a,n,x,y);
while(x<0)
{
x=x+n;
}
g<<x;
}