Find The Number Of Common Divisors That Are Greater Than 1 Of All SubArrays N<=1e5,2<=ai<=1e5 Ans Mod 1e9+7 First TestCase : 3
2 10 15 , Ans = 9
Second TestCase : 6
3 6 11 22 44 2 , Ans = 22
Thanks In Advance
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3390 |
| 6 | Um_nik | 3387 |
| 7 | tourist | 3384 |
| 8 | heuristica | 3322 |
| 9 | turmax | 3319 |
| 10 | jiangbowen | 3291 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 143 |
| 5 | AmShZ | 142 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | maroonrk | 134 |
| 9 | BledDest | 132 |
| 10 | qwexd | 129 |
Find The Number Of Common Divisors That Are Greater Than 1 Of All SubArrays N<=1e5,2<=ai<=1e5 Ans Mod 1e9+7 First TestCase : 3
2 10 15 , Ans = 9
Second TestCase : 6
3 6 11 22 44 2 , Ans = 22
Thanks In Advance
| Название |
|---|



Auto comment: topic has been updated by HaveYouEverOrNever (previous revision, new revision, compare).
To solve this problem, we can use the fact that the number of common divisors of a set of numbers is equal to the number of divisors of their greatest common divisor (GCD). Therefore, we can compute the GCD of all subarrays of the given array and count the number of divisors of each GCD that are greater than 1.
To efficiently compute the GCD of all subarrays, we can use a segment tree. We can build a segment tree where each node represents the GCD of a range of elements. Initially, the root of the tree represents the GCD of the entire array. Then, we can recursively compute the GCD of the left and right subranges of each node to build the tree.
Once we have built the segment tree, we can traverse it to compute the GCD of all subarrays. For each node of the tree, we can compute the GCD of its corresponding range of elements by combining the GCDs of its left and right subranges. Then, we can count the number of divisors of the GCD that are greater than 1 and add it to the final answer.
Even without seg tree or any range query data structure, it's possible. A hint is that the gcd of a subarray, when we fix its left endpoint and keep moving rightwards, can only change $$$O(logM)$$$ times where $$$M$$$ is the maximum element in the array.
Can You Explain This Part In Code ? thanks in advance