Luzhiled's Library

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

View the Project on GitHub ei1333/library

:warning: Floor Div(床除算) (other/floor-div.hpp)

整数の床除算を求めます。

floor_div

T floor_div(T n, T d)

$\lfloor \frac{n}{d} \rfloor$ を返します。

制約

  • T は符号付き整数型
  • $d \ne 0$

計算量

  • $O(1)$

Code

template <typename T>
T floor_div(T n, T d) {
  static_assert(is_integral<T>::value and is_signed<T>::value,
                "template parameter T must be signed integral type");
  return n / d - ((n ^ d) < 0 && n % d != 0);
}
#line 1 "other/floor-div.hpp"
template <typename T>
T floor_div(T n, T d) {
  static_assert(is_integral<T>::value and is_signed<T>::value,
                "template parameter T must be signed integral type");
  return n / d - ((n ^ d) < 0 && n % d != 0);
}
Back to top page