quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryالرياضيات schoolبكالوريوس event_available2026-07-15

السؤال

Transcribed Image Text:

5. Paint the ceiling You want to build yourself a house. The building company you hired can only build houses with sides from their specific sets. 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 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 so, 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 For example, you are given s[0] = s0 = 2 and they will produce n = 3 total wall lengths. If k = 3, b = 3 and m = 2 we have: S i [2] 1 [2,4] 2 calculation ((3*2+3)%2)+1+2 4 ((3*4+3)%2)+1+4 6 result [2,4,6] Now that we have our set of lengths, we can brute force the solution using the following tests assuming a = 15: s [2, 4, 6] sl s2 s1*s2 s1*s2 <= 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. Function Description Complete the function variantsCount in the editor below. The function must return an integer that denotes the number of variants that allow you to use the promotion. variantsCount has the following parameter(s): n: an integer, the number of wall lengths offered s0: an integer, the length of the shortest wall k, b, m: three arbitrary integers a: a long integer, the largest area that will be painted for free Constraints • 1 sn≤6*107 • 1≤ s[i]≤ 109,0≤i≤n •1sk, b, m≤ 10⁹ • 1 sa≤ 1018 ► Input Format for Custom Testing ▼ Sample Case 0 Sample Input 3 1 1 1 2 4 Sample Output 6

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top