Cod sursa(job #1666980)
Utilizator | Data | 28 martie 2016 15:46:24 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
#define ll long long
using namespace std;
ll t,n,z;
void euclid(ll a, ll b, ll &x, ll &y)
{
if(b==0)
{
x=1;
y=0;
}
else{
euclid(b,a%b,x,y);
ll q=x;
x=y;
y=q-(a/b)*y;
}
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>t>>n;
ll x1=0,y1;
euclid(t,n,x1,y1);
while(x1<=0)
x1=n+x1%n;
g<<x1;
return 0;
}