Nu aveti permisiuni pentru a descarca fisierul grader_test7.in
Cod sursa(job #1458455)
| Utilizator | Data | 7 iulie 2015 15:57:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
//Invers Modular
#include <fstream>
using namespace std;
void EuclidExtended(int a, int b, int &d, int &x, int &y)
{
if(!b)
{
d = a;
x = 1;
y = 0;
}
else
{
int x0,y0;
EuclidExtended(b,a%b,d,x0,y0);
x = y0;
y = x0 - (a/b) * y0;
}
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n,d,x,y;
f>>a>>n;
EuclidExtended(a,n,d,x,y);
while(x < 0 )
{
x+=n;
}
g<<x % n ;
return 0;
}
