Cod sursa(job #2867579)
| Utilizator | Data | 10 martie 2022 13:58:18 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#include <bitset>
#include <vector>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,n,v1,v2;
void Euclid(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1; y=0;
}
else
{
Euclid(b,a%b,x,y);
int cx=x;
x=y;
y=cx-y*(a/b);
}
}
int main()
{
fin>>a>>n;
Euclid(a,n,v1,v2);
while(v1<=0) v1+=n;
fout<<v1;
return 0;
}
