Cod sursa(job #729001)
Utilizator | Data | 29 martie 2012 10:22:32 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid(int a,int b,int &x, int &y,int &d){
if(!b){
x=1;
y=0;
d=a;
return;
}
int x1,y1,q=a/b;
euclid(b,a%b,x1,y1,d);
x=y1;
y=x1-q*y1;
}
int main(){
int x,y,a,n,d=1;
in>>a>>n;
euclid(a,n,x,y,d);
if(x>n-1)
x%=10;
out<<x;
return 0;
}