Cod sursa(job #2540609)
Utilizator | Data | 7 februarie 2020 12:51:22 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void invmod(long long &x,long long &y,int a,int b){
if(b==0)
x=1,y=0;
else{
invmod(x,y,b,a%b);
long long c=x;
x=y;
y=c-y*(a/b);
}
}
int main(){
long long a,b,x=0,y=0;
fin>>a>>b;
invmod(x,y,a,b);
if(x<=0){
x=b+x%b;
}
fout<<x;
}