Problem Statement You want to build yourself a house. The building company you hired can…
- User
Problem Statement You want to build yourself a house. The building company you hired can only build houses with sides from their specific set 𝑠 s. This means they can build you a square house or a rectangular one, but if and only if its length and width belong to the set 𝑠 s.
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 𝑠 0 s 0 , some variables 𝑘 k, 𝑏 b, and 𝑚 m, and use the following equation to determine all other side lengths 𝑠 [ 𝑖 ] s[i]:
𝑠 [ 𝑖 ]
( ( 𝑘 × 𝑠 [ 𝑖 − 1 ] + 𝑏 ) m o d 𝑚 ) + 𝑠 [ 𝑖 − 1 ] for 1 ≤ 𝑖 < 𝑛 s[i]=((k×s[i−1]+b)modm)+s[i−1] for 1≤i<n For example, you are given 𝑠 [ 0 ]
𝑠 0
2 s[0]=s 0 =2 and they will produce 𝑛
3 n=3 total wall lengths. If 𝑘
3 k=3, 𝑏
3 b=3, and 𝑚
2 m=2, we have:
𝑠 [ 1 ]
( ( 3 × 2 + 3 ) m o d 2 ) + 2
4 s[1]=((3×2+3)mod2)+2=4 𝑠 [ 2 ]
( ( 3 × 4 + 3 ) m o d 2 ) + 4
6 s[2]=((3×4+3)mod2)+4=6 Thus, 𝑠
[ 2 , 4 , 6 ] s=[2,4,6].
Now that we have our set of lengths, we can brute-force the solution using the following tests, assuming 𝑎
15 a=15:
Pairs like (2, 2), (2, 4), etc., are tested to see if 𝑠 1 × 𝑠 2 ≤ 𝑎 s 1 ×s 2 ≤a. There are 5 combinations that will result in a free paint job. Function Description: Write a function variantsCount that returns the number of variants that allow you to use the promotion.
Parameters:
𝑛 n: integer, the number of wall lengths offered. 𝑠 0 s 0 : integer, the length of the shortest wall. 𝑘 , 𝑏 , 𝑚 k,b,m: three arbitrary integers. 𝑎 a: long integer, the largest area that will be painted for free. Constraints:
1 ≤ 𝑛 ≤ 2 × 1 0 7 1≤n≤2×10 7
1 ≤ 𝑠 [ 𝑖 ] ≤ 1 0 9 , 0 ≤ 𝑖 < 𝑛 1≤s[i]≤10 9 ,0≤i<n 1 ≤ 𝑘 , 𝑏 , 𝑚 ≤ 1 0 9 1≤k,b,m≤10 9
1 ≤ 𝑎 ≤ 1 0 18 1≤a≤10 18
Sample Input:
Copy code 3 1 1 1 2 4 Sample Output:
Copy code 6
wait for me to give the driver's code
- Assistant