Cod sursa(job #2107076)
| Utilizator | Data | 16 ianuarie 2018 18:49:29 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void EuclidE(long long a,long long b,long long &x,long long &y, long long &d){
if(b==0){
x=1;
d=a;
y=0;
}
else{
long long x0,y0;
EuclidE(b,a%b,x0,y0,d);
x=y0;
y=x0-a/b*y0;
}
}
long long A,N,x,y,d;
int main()
{
in>>A>>N;
EuclidE(N,A,x,y,d);
while(y<1){y+=N;}
out<<y;
in.close();
out.close();
return 0;
}
