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

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

Please provide the approach of the following ,I have tried but i didn't came up with a good approach

You are given an array A of length N and an integer K. It is given that a number m is called special if gcd(m,Aj) = 1 for all 0<=j<N

Let R be an array containing all special number in the range [ 1 , K ] inclusive in sorted order . Your task is to return R.

Note : A follows 0-based indexing.

Input Format The first line contains an integer N , denoting the number of elements in A. The next line contains an integer K , denoting the given integer. Each line i of the N subsequent lines (where 0<=i<N) contains an integer describing A[i].

Constraints 1<=N<=10^5 1<=K<=10^5 1<=A[i]<=10^5

Sample Input Sample Output 3 1 5 5 1 2 3

4 1 5 2 3 4 3 5 7

4 1 1 1 1 1 1

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

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

For all x in [1, K], for all prime p such that p divides x if p doesn't divide any A[i] (0 <= i < N) then include x in our ans.

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

Use the fact that you can find divisors of a number ai in sqrt(ai). Maintain a set which initially contains all numbers from 1 to k. For each ai, for each divisor if the divisor is in set then remove it. The set contains all your numbers.

Complexity: O((N*sqrt(Ai)+K)*logK)