competitive-programming-library

This documentation is automatically generated by online-judge-verify-helper

View the Project on GitHub kmyk/competitive-programming-library

:warning: monoids/gcd.hpp

Back to top page

Depends on

Code

#pragma once
#include "number/gcd.hpp"

/**
 * @note a semilattice
 */
struct gcd_monoid {
    typedef int value_type;
    int unit() const { return 0; }
    int mult(int a, int b) const { return gcd(a, b); }
};

#line 2 "number/gcd.hpp"
#include <algorithm>

/**
 * @note if arguments are negative, the result may be negative
 */
template <typename T>
T gcd(T a, T b) {
    while (a) {
        b %= a;
        std::swap(a, b);
    }
    return b;
}

template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
#line 3 "monoids/gcd.hpp"

/**
 * @note a semilattice
 */
struct gcd_monoid {
    typedef int value_type;
    int unit() const { return 0; }
    int mult(int a, int b) const { return gcd(a, b); }
};

Back to top page