Cod sursa(job #2329471)
| Utilizator | Data | 26 ianuarie 2019 20:03:05 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <cstdio>
using namespace std;
FILE *f,*g;
void inv(long long a,long long b,long long &x,long long &y)
{
if(!b)
x=1,y=0;
else
{
inv(b,a%b,x,y);
int aux=x;
x=y;
y=x-a/b*y;
}
}
int main()
{
f=fopen("inversmodular.in","r");
g=fopen("inversmodular.out","w");
long long nr,mod,x,y;
fscanf(f,"%lld %lld",&nr,&mod);
inv(nr,mod,x,y);
if(x<=0)
x=mod+x%mod;
fprintf(g,"%lld\n",x);
fclose(f);
fclose(g);
return 0;
}
