Cod sursa(job #2312177)
Utilizator | Data | 4 ianuarie 2019 13:50:41 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 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);
if (s<0) fout<<s%n+n; else
fout<<s;
return 0;
}