Cod sursa(job #1921176)
Utilizator | Data | 10 martie 2017 11:39:21 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int w;
int cmmdc(int a,int b)
{
while(b)
{
w=a%b;
a=b;
b=w;
}
return a;
}
void euclid(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
int x0,y0;
euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
int t,a,b,c,d,e,x,y;
f>>a>>b;
euclid(a,b,x,y);
while(x<0)
x+=b;
g<<x;
return 0;
}