Luzhiled's Library

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

View the Project on GitHub ei1333/library

:warning: Sum of Geometric Sequence(等比数列の和)
(math/combinatorics/sum-of-geometric-sequence.hpp)

Code

/**
 * @brief Sum of Geometric Sequence(等比数列の和)
 */
template< typename Mint >
Mint sum_of_geometric_sequence(const Mint &a, const Mint &r, const int64_t &n) {
  assert(r != Mint(0));
  return r == Mint(1) ? a * n : a * (r.pow(n) - 1) / (r - 1);
}
#line 1 "math/combinatorics/sum-of-geometric-sequence.hpp"
/**
 * @brief Sum of Geometric Sequence(等比数列の和)
 */
template< typename Mint >
Mint sum_of_geometric_sequence(const Mint &a, const Mint &r, const int64_t &n) {
  assert(r != Mint(0));
  return r == Mint(1) ? a * n : a * (r.pow(n) - 1) / (r - 1);
}
Back to top page