Блог пользователя HaveYouEverOrNever

Автор HaveYouEverOrNever, история, 4 года назад, По-английски

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
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Auto comment: topic has been updated by HaveYouEverOrNever (previous revision, new revision, compare).

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.