FastPrepPaint the Ceiling
Problem · Array

Paint the Ceiling

Learn this problem
â—Ź MediumWeride logoWerideFULLTIMEOA

Problem 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) → long

Examples

Example 1

s0 = 2n = 3k = 3b = 3m = 2a = 15return = 5

The 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^9
  • 1 <= n <= 6 * 10^6
  • 1 <= a <= 10^18

More Weride problems

drafts saved locally
public long paintTheCeiling(int s0, int n, int k, int b, int m, long a) {
    // Write your code here
}
s02
n3
k3
b3
m2
a15
expected5
checking account