Cod sursa(job #1734838)
Utilizator | Tifui Ioan Alexandru tifui.alexandru | Data | 28 iulie 2016 13:21:45 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(long long a,long long n,long long &x,long long &y)
{
if(!n)
{
x=1;
y=0;
return;
}
long long x1,y1;
euclid(n,a%n,x1,y1);
x=y1;
y=x1-(a/n)*y1;
}
int main()
{
long long a,n,x,y;
f>>a>>n;
euclid(a,n,x,y);
while(x<0)
x+=n;
g<<x<<'\n';
return 0;
}
// 70-80 puncte