Pagini recente » Cod sursa (job #597881) | Cod sursa (job #3242213) | Cod sursa (job #23185) | Cod sursa (job #1068701) | Cod sursa (job #998028)
Cod sursa(job #998028)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
const string file = "inversmodular";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
int euclidExtins(int a, int b, int& x, int& y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int x0 = 0;
int y0 = 0;
int d = euclidExtins(b, a % b, x0, y0);
x = y0;
y = x0 - (a /b)*y0;
return d;
}
}
int main()
{
fstream fin(infile.c_str(), ios::in);
int a, b;
fin >> a >> b;
fin.close();
int x;
int y;
int d = euclidExtins(a, b, x, y);
while(x < 0)
x += b;
while(x > b)
x -= b;
fstream fout(outfile.c_str(), ios::out);
fout << x << "\n";
fout.close();
}