Cod sursa(job #1132963)
| Utilizator | Data | 4 martie 2014 10:34:29 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long int A,N,x,y,d,c;
void extins(long long int a, long long int b, long long int &d, long long int &x, long long int &y){
if(b==0){
d=a;
x=1;
y=0;
}
else{
long long int x0,y0;
extins(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main(){
f>>A>>N;
c=1;
extins(A,N,d,x,y);
if(x>0)
g<<x*c/d;
else{
while(x<0){
x+=N;
}
g<<x*c/d;
}
return 0;
}
