Cod sursa(job #2312175)
Utilizator | Data | 4 ianuarie 2019 13:49:32 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int n,a,i; long long y,s=3;
void inv(long long &x,long long &y,int a,int b )
{
if (!b)
{
x=1;
y=0;
return;
}
inv(x,y,b,a%b);
i=x;
x=y;
y=i-(a/b)*y;
}
int main()
{
fin>>a>>n;
inv(s,y,a,n);
fout<<s;
return 0;
}