Pagini recente » Cod sursa (job #1604205) | Cod sursa (job #732173) | Diferente pentru problema/text2 intre reviziile 9 si 12 | Diferente pentru problema/treesearch intre reviziile 18 si 23 | Cod sursa (job #2086558)
#include<fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a,n,x,y;
void ve(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
long long x1,y1,c;
ve(b,a%b,x1,y1);
c=a/b;
x=y1;
y=x1-c*y1;
}
int main()
{
fin>>a>>n;
ve(a,n,x,y);
while(x<0)
x+=n;
fout<<x;
}