Cod sursa(job #2784433)
| Utilizator | Data | 16 octombrie 2021 14:30:00 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <cstdio>
using namespace std;
FILE *f=fopen("inversmodular.in","r");
FILE *g=fopen("inversmodular.out","w");
void euclid(long long a, long long b, long long &d, long long &x, long long &y){
if(!b){
d=a;
x=1;
y=0;
return;
}
long long x1,y1;
euclid(b,a%b,d,x1,y1);
x=y1;
y=x1-y1*(a/b);
}
int main()
{
long long a,b,d,x,y;
fscanf(f,"%lld%lld",&a,&b);
euclid(a,b,d,x,y);
while(x<0){
x+=a;
}
fprintf(g,"%lld",x);
}
