Pagini recente » Cod sursa (job #1405381) | Cod sursa (job #490319) | Cod sursa (job #3270742) | Cod sursa (job #1136159)
#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>
#include <iterator>
#include <random>
#include <assert.h>
using namespace std;
const string file = "inversmodular";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
//#define ONLINE_JUDGE
int euclidExtins(int a, int b, int& x, int& y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
else
{
int x0, y0;
int d = euclidExtins(b, a % b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
return d;
}
}
int main()
{
#ifdef ONLINE_JUDGE
ostream &fout = cout;
istream &fin = cin;
#else
fstream fin(infile.c_str(), ios::in);
fstream fout(outfile.c_str(), ios::out);
#endif
int A, N;
fin >> A >> N;
int x, y;
int d = euclidExtins(A, N, x, y);
while(x < 0) x += N;
while(x >= N) x -= N;
fout << x << "\n";
#ifdef ONLINE_JUDGE
#else
fout.close();
fin.close();
#endif
}