Paint the Ceiling
Learn this problemProblem statement
You want to build yourself a house. The building company you hired can only build houses with sides from their specific set s. That means they can build you a square house or a rectangular one but if and only if its length and width belong to the sets.
This month, they have a special promotion: they will paint the ceiling of a new house for free... but only if its area is not more than a. You want them to do it for free but you also want to be sure that the house will be comfortable and not too small. How many possible house configurations can you create to have the ceiling painted for free given the side lengths offered?
There is a method to how the company decides what lengths of sides to produce. To determine n lengths of wall segments to offer, they start with a seed value s0, some variables k, b and m, and use the following equation to determine all other side lengths s_i:
s_i = (( k * s_{i-1} + b)mod m+1+s_{i-1}) for 1 <= i < n
Function
paintTheCeiling(s0: int, n: int, k: int, b: int, m: int, a: long) → long
Complete the function paintTheCeiling in the editor.
paintTheCeiling has the following parameters:
s0: an integer, the seed value for side lengthsn: an integer, the number of side lengths to producek: an integerb: an integerm: an integera: a long integer, the maximum area for a free paint job
Returns
long integer: the number of possible house configurations
Examples
Example 1
s0 = 2n = 3k = 3b = 3m = 2a = 15return = 5
a=15:
s=[2,4,6]
s1 s2 s1xs2 s1xs2≤a
2 2 4 True
2 4 8 True
2 6 12 True
4 2 8 True
4 4 16 False
4 6 24 False
6 2 12 True
6 4 24 False
6 6 36 False
There are 5 combinations that will result in a free paint job. Brute force will not meet the time constraints on large sets.
Constraints
1 ≤ n ≤ 6 x 10^61 ≤ s_i ≤ 10^91 ≤ k, b, m ≤ 10^91 ≤ a ≤ 10^18
More Snowflake problems
- Minimum N-ary Tree Depth DeletionsPHONE SCREEN · Seen Jul 2026
- Simulate a Queued Multi-Rule Rate LimiterPHONE SCREEN · Seen Jul 2026
- Minimum Clicks Between Wiki PagesOA · Seen Jul 2026
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerOA · Seen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringOA · Seen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026