spl

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Forestedf/spl

:heavy_check_mark: number_theory/barrett.hpp

Required by

Verified with

Code

#pragma once

struct Barrett {
    unsigned m;
    unsigned long long im;
    explicit Barrett(unsigned m) : m(m), im(-1ull / m + 1) {}
    unsigned mul(unsigned x, unsigned y) const {
        unsigned long long z = (unsigned long long)x * y;
        unsigned long long q = ((__uint128_t)z * im) >> 64;
        unsigned long long t = q * m;
        return z - t + (z < t ? m : 0);
    }
};
#line 2 "number_theory/barrett.hpp"

struct Barrett {
    unsigned m;
    unsigned long long im;
    explicit Barrett(unsigned m) : m(m), im(-1ull / m + 1) {}
    unsigned mul(unsigned x, unsigned y) const {
        unsigned long long z = (unsigned long long)x * y;
        unsigned long long q = ((__uint128_t)z * im) >> 64;
        unsigned long long t = q * m;
        return z - t + (z < t ? m : 0);
    }
};
Back to top page