Problems > Count Pentagonals in a Range > Editorial

Count Pentagonals in a Range — Solution & Editorial

Back to the Problem

Prefix counting: (how many ≤ R) − (how many ≤ L−1); the count-up-to function inverts the sequence's closed form (integer roots, bit length, or a precomputed list).

Complexity: O(1) or O(log)

Watch out: Everything must be exact integer arithmetic — floating-point roots drift at 1018.