Mai intai trebuie sa te autentifici.
Cod sursa(job #1164749)
Utilizator | Data | 2 aprilie 2014 12:00:41 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long int a,n,x,y,d;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(long long int a,long long int b,long long int d,long long int &x,long long int &y){
if(b==0)
{
x=1;
y=0;
}
else
{
long long int x0,y0;
euclid(b,a%b,1,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
f>>a>>n;
euclid(a,n,1,x,y);
while(x<0)
x+=n;
g<<x;
return 0;
}