ku-library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub kogetsu0728/ku-library

:heavy_check_mark: test/math/extended_gcd.test.cpp

Depends on

Required by

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E"

#include "../../math/extended_gcd.hpp"
#include "../../template/template.hpp"

int main() {
    ll a, b;
    cin >> a >> b;

    ll x, y;
    ext_gcd(a, b, x, y);

    cout << x << ' ' << y << LF;

    return 0;
}
#line 1 "test/math/extended_gcd.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E"

#line 2 "math/extended_gcd.hpp"

/**
 * @brief Extended Euclidean Algorithm (拡張ユークリッドの互除法)
 * @note 参考: https://qiita.com/drken/items/b97ff231e43bce50199a
 */
template <class T>
T ext_gcd(T a, T b, T& x, T& y) {
    if (b == T(0)) {
        x = T(1);
        y = T(0);

        return a;
    }

    T res = ext_gcd(b, a % b, y, x);
    y -= (a / b) * x;

    return res;
}
#line 2 "template/template.hpp"

/**
 * @author ku_senjan
 * @title 提出用テンプレート
 * @see https://github.com/kogetsu0728/ku-library
 */

#line 2 "template/constant.hpp"

#line 2 "template/include.hpp"

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
#line 2 "template/type_alias.hpp"

#line 4 "template/type_alias.hpp"

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

using ld = long double;

template <class T, bool REVERSE = false>
using heap = priority_queue<T, vector<T>, conditional_t<REVERSE, greater<T>, less<T>>>;
#line 5 "template/constant.hpp"

template <class T>
inline constexpr T INF = numeric_limits<T>::max() / 2;

inline constexpr array<int, 4> DY4 = {0, -1, 0, 1};
inline constexpr array<int, 4> DX4 = {1, 0, -1, 0};
inline constexpr array<int, 8> DY8 = {0, -1, -1, -1, 0, 1, 1, 1};
inline constexpr array<int, 8> DX8 = {1, 1, 0, -1, -1, -1, 0, 1};

inline constexpr char LF = '\n';
#line 2 "template/macro.hpp"

#line 5 "template/macro.hpp"

/**
 * @see https://trap.jp/post/1224/
 */

#ifdef LOCAL
inline constexpr bool IS_LOCAL = true;
#else
inline constexpr bool IS_LOCAL = false;
#endif

#define IF_LOCAL if constexpr (IS_LOCAL)

#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)

#define overload4(a, b, c, d, e, ...) e

#define rep1(i, a) for (ll i = 0; (i) < (ll)(a); ++(i))
#define rep2(i, a, b) for (ll i = (ll)(a); (i) < (ll)(b); ++(i))
#define rep3(i, a, b, c) for (ll i = (ll)(a); (i) < (ll)(b); (i) += (ll)(c))
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep1(i, a) for (ll i = (ll)(a); (i) >= 0; --(i))
#define rrep2(i, a, b) for (ll i = (ll)(a); (i) >= (ll)(b); --(i))
#define rrep3(i, a, b, c) for (ll i = (ll)(a); (i) >= (ll)(b); (i) -= (ll)(c))
#define rrep(...) overload4(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#line 13 "template/template.hpp"

#line 2 "utility/choose_min_max.hpp"

/**
 * @title Choose Minimum / Maximum
 */

template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }

    return false;
}

template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }

    return false;
}
#line 2 "utility/set_io.hpp"

#line 4 "utility/set_io.hpp"

void set_io(int d = 16) {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(d);

    return;
}
#line 5 "test/math/extended_gcd.test.cpp"

int main() {
    ll a, b;
    cin >> a >> b;

    ll x, y;
    ext_gcd(a, b, x, y);

    cout << x << ' ' << y << LF;

    return 0;
}

Test cases

Env Name Status Elapsed Memory
g++ 00_sample_00.in :heavy_check_mark: AC 5 ms 4 MB
g++ 00_sample_01.in :heavy_check_mark: AC 4 ms 4 MB
g++ 01_small_00.in :heavy_check_mark: AC 4 ms 4 MB
g++ 01_small_01.in :heavy_check_mark: AC 4 ms 3 MB
g++ 01_small_02.in :heavy_check_mark: AC 4 ms 4 MB
g++ 01_small_03.in :heavy_check_mark: AC 4 ms 4 MB
g++ 01_small_04.in :heavy_check_mark: AC 4 ms 4 MB
g++ 01_small_05.in :heavy_check_mark: AC 4 ms 4 MB
g++ 02_critical_00.in :heavy_check_mark: AC 4 ms 4 MB
g++ 02_critical_01.in :heavy_check_mark: AC 4 ms 4 MB
g++ 02_critical_02.in :heavy_check_mark: AC 4 ms 4 MB
g++ 02_critical_03.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_00.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_01.in :heavy_check_mark: AC 4 ms 3 MB
g++ 03_large_02.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_03.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_04.in :heavy_check_mark: AC 4 ms 3 MB
g++ 03_large_05.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_06.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_07.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_08.in :heavy_check_mark: AC 4 ms 4 MB
g++ 03_large_09.in :heavy_check_mark: AC 4 ms 4 MB
g++ 04_corner_00.in :heavy_check_mark: AC 4 ms 4 MB
g++ 04_corner_01.in :heavy_check_mark: AC 4 ms 4 MB
g++ 04_corner_02.in :heavy_check_mark: AC 4 ms 4 MB
g++ 04_corner_03.in :heavy_check_mark: AC 4 ms 3 MB
g++ 05_rand_00.in :heavy_check_mark: AC 4 ms 4 MB
g++ 05_rand_01.in :heavy_check_mark: AC 4 ms 4 MB
g++ 05_rand_02.in :heavy_check_mark: AC 4 ms 3 MB
g++ 05_rand_03.in :heavy_check_mark: AC 4 ms 4 MB
g++ 05_rand_04.in :heavy_check_mark: AC 4 ms 4 MB
g++ 05_rand_05.in :heavy_check_mark: AC 4 ms 3 MB
Back to top page