Pagini recente » Cod sursa (job #2906799) | Cod sursa (job #861180) | Cod sursa (job #2616525) | Cod sursa (job #2127486) | Cod sursa (job #631277)
Cod sursa(job #631277)
#include<fstream>
using namespace std;
int a,n;
long long x=1,y,tmp;
void euclid(int a,int b) {
if(b) {
euclid(b,a%b);
tmp=x;
x=y;
y=tmp-y*(a/b);
}
}
int main() {
int a,n;
ifstream in("inversmodular.in");
in>>a>>n;
in.close();
euclid(a,n);
if(x<1) x=n+x%n;
ofstream out("inversmodular.out");
out<<x<<'\n';
out.close();
return 0;
}