Problem · Array
Paint the Ceiling
Learn this problemProblem statement
Generate a strictly increasing sequence of n positive side lengths:
s[0] = s0- For each
1 <= i < n,s[i] = ((k * s[i - 1] + b) mod m) + 1 + s[i - 1].
Count the ordered pairs of indices (i, j) such that a rectangle with side lengths s[i] and s[j] has area at most a. Both orientations count separately when the side lengths differ, and a square may use the same generated length for both sides.
Return the number of qualifying ordered pairs.
Function
paintTheCeiling(s0: int, n: int, k: int, b: int, m: int, a: long) → longExamples
Example 1
s0 = 2n = 3k = 3b = 3m = 2a = 15return = 5The generated sequence is [2, 4, 6]. The qualifying ordered pairs of side lengths are (2, 2), (2, 4), (2, 6), (4, 2), and (6, 2), for a total of 5.
Constraints
1 <= s0, k, b, m <= 10^91 <= n <= 6 * 10^61 <= a <= 10^18