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

Автор i_am_not_special, история, 20 месяцев назад, По-английски

So the question is count the number of increasing subsequence such that the gcd of subsequence will be equal to 1.

1 <= size of array <= 1e5 1 <= a[i] <= 1e6

can anyone help me solve this problem.

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

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

0(n) = 0 * n = 0, wtf??

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

Create a another array called primes which will have all the prime numbers in the given array in the same seqvence of the array and now create an another array called ream where ream[i] is how many numbers which are greater than primes[i] and right side of primes[i]. Now answer is sum of 2**k for each k in ream (pardon me if it's wrong).
For finding primes we can use Sieve of Eratosthenes.
For building ream array we can use merge sort (or) fenwick tree.

»
20 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +21 Проголосовать: не нравится

Let $$$\operatorname{count}_x$$$ be the number of integers which are divisible by $$$x$$$ in the array. Now let $$$\operatorname{dp}_x$$$ be the number of subsequences whose gcd is $$$x$$$. We can calculate $$$\operatorname{dp}_x$$$ from highest to lowest $$$x$$$-value. Initially we set $$$\operatorname{dp}_x = 2^{\operatorname{count}_x} - 1$$$. Then, we subtract all $$$\operatorname{dp}_y$$$ values where $$$y$$$ is a multiple of $$$x$$$.

Now you have the number of subsequences with a gcd of any $$$x$$$ in the $$$\operatorname{dp}$$$ array. You can use this same strategy to count the number of pairs with a gcd of $$$x$$$.

Edit: Sorry, this doesn't count increasing subsequences, I misread the problem. My fault.

Edit 2: Somebody replied to me, showing how you can extend this solution to work with increasing subsequences :)

»
20 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

why is this being upvoted, op literally said OA problem (and literally noone asked if it is ongoing or not)