Pagini recente » Diferente pentru problema/dummy intre reviziile 15 si 14 | Cod sursa (job #255302) | Monitorul de evaluare | Cod sursa (job #2600886) | Cod sursa (job #2312177)
#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;
}