Cod sursa(job #2313754)
Utilizator | Data | 7 ianuarie 2019 13:53:52 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
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;
}