Cod sursa(job #2574236)
| Utilizator | Data | 5 martie 2020 21:03:23 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | r3capitusulare | Marime | 0.57 kb |
#include <fstream>
#define ios ios_base::sync_with_stdio(false);
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int a,n;
void invmod(long long &x,long long &y,int a,int b){
if (!b){
x=1; y=0;
}
else{
invmod(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-(a/b)*y;
}
}
int main()
{
ios;
cin.tie(0);
cout.tie(0);
long long invm,aj;
cin>>a>>n;
invmod (invm,aj,a,n);
if (invm<0) invm=n+invm%n;
cout<<invm;
return 0;
}
