NumberTheory/Math/test/aizu_ntl_1_e_extended_euclid.test.cpp
Depends on
Code
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E"
#include "../../../template.h"
#include "../Extended_euclid.h"
void solve() {
int a, b; cin >> a >> b;
int x, y;
int g = extended2(a, b, x, y);
cout << x << " " << y << '\n';
}
#line 1 "NumberTheory/Math/test/aizu_ntl_1_e_extended_euclid.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E"
#line 2 "template.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)(1e9+7)
#define all(x) (x).begin(),(x).end()
#define unique(x) x.erase(unique(all(x)), x.end())
#define INF32 ((1ull<<31)-1)
#define INF64 ((1ull<<63)-1)
#define inf (ll)1e18
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int mod = 998244353;
void solve();
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
// cin.exceptions(cin.failbit);
// int t; cin >> t;
// while(t--)
solve();
cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << '\n';
return 0;
}
#line 2 "NumberTheory/Math/Extended_euclid.h"
int extended1(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int x1, y1;
int d = extended1(b, a%b, x1, y1);
x = y1;
y = x1-y1*(a/b);
return d;
}
// Iterative version
int extended2(int a, int b, int &x, int &y) {
x = 1, y = 0;
int x1 = 0, y1 = 1;
int a1 = a, b1 = b;
while (b1) {
int q = a1 / b1;
tie(x, x1) = make_tuple(x1, x - q * x1);
tie(y, y1) = make_tuple(y1, y - q * y1);
tie(a1, b1) = make_tuple(b1, a1 - q * b1);
}
return a1;
}
#line 5 "NumberTheory/Math/test/aizu_ntl_1_e_extended_euclid.test.cpp"
void solve() {
int a, b; cin >> a >> b;
int x, y;
int g = extended2(a, b, x, y);
cout << x << " " << y << '\n';
}
Back to top page