Cod sursa(job #397686)
| Utilizator | Data | 17 februarie 2010 12:37:16 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
using namespace std;
void euclid( long long A, long long B, long long &x, long long &y){
if( B == 0 ){
x = 1;
y = 0;
return;
}
long long X0,Y0;
euclid( B, A%B, X0, Y0);
x = Y0;
y = X0 - ( A/B ) * Y0;
}
int main(){
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long A,N,x,y;
f>>A>>N;
euclid(A,N,x,y);
if( x<0 ) g<<N + x%N;
else g<<x%N;
return 0;
}
