230#ifndef __ADS_NumberTheory
231 #define __ADS_NumberTheory
250#include <type_traits>
317inline std::tuple< long long , long long , long long >
416 [[nodiscard]]
constexpr U64 modulus(
void )
const {
return( f_n ); }
425 [[nodiscard]]
constexpr U64 from(
U64 x )
const {
return( reduce( 0 , x ) ); }
428 [[nodiscard]]
constexpr U64 one(
void )
const {
return( f_one ); }
443 [[nodiscard]] [[gnu::always_inline]]
constexpr U64 mul(
U64 a ,
U64 b )
const;
482 [[nodiscard]] [[gnu::always_inline]]
constexpr U64 reduce(
U64 hi ,
683#include "ADS/numeric/impl/NumberTheory.tpp"
The SET of the integers in as a boolean vector of section 8.1: contains(), insert() and remove() in ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of...
constexpr U64 modulus(void) const
the modulus
Definition NumberTheory.h:416
constexpr U64 one(void) const
the form of 1
Definition NumberTheory.h:428
constexpr U64 from(U64 x) const
the number whose form is , as
Definition NumberTheory.h:425
constexpr U64 to(U64 x) const
the form of , as
constexpr U64 mul(U64 a, U64 b) const
the form of the product of the numbers of the forms and
constexpr Montgomery64(U64 n)
the arithmetic modulo , with one division of 128 bits for
constexpr U64 pow(U64 x, U64 v) const
the form of , a form
constexpr U64 binaryGcd(U64 a, U64 b)
the greatest common divisor of and by the binary algorithm, with no division;
std::vector< U64 > factorize(U64 n)
the prime factors of , with their multiplicity, increasing, by the divisions by the primes below 4096...
U64 powMod(U64 x, U64 v, U64 m)
the power by repeated squaring, the products of Montgomery when is odd
bool isPrime(U64 n)
the primality of , exact for every of 64 bits
bool witness(U64 n, U64 b)
true if is a witness that the odd is composite
std::vector< U64 > sieve(U64 n)
the primes up to , increasing, by the sieve of Eratosthenes
U64 gcd(U64 s, U64 m)
the greatest common divisor by the algorithm of Euclid, steps
constexpr U64 kMersenne61
the Mersenne prime
Definition NumberTheory.h:339
std::tuple< long long, long long, long long > extendedEuclid(long long s, long long m)
the triple with (the euclideEsteso() of the book)
long long modInverse(long long s, long long m)
the inverse of , with ; a violation of the precondition if
bool millerRabin(U64 n, int K, R &rng)
the primality of by the test of Miller and Rabin on random bases, wrong with probability at most ,...
bool isPrimeTrial(U64 n)
the primality of by the divisions by (the primo() of the book)
constexpr U64 mulMod(U64 a, U64 b, U64 m)
the product , exact for any , and : by the product of 64 bits for , by mulMod61() for ,...
constexpr U64 mulMod61(U64 a, U64 b)
the product , , by four products of 32 bits and the folding
std::uint64_t U64
the unsigned integers of 64 bits
Definition NumberTheory.h:261