Modify the array

Revision en2, by confusedcoder, 2016-05-26 09:22:33

We have an array, Let's call it A, with upto 5*10^5 elements and each element <=10^6, and Q-the number of queries. Q<=5*10^5.
In ith query- 1<=i<=Q , we need to find the prime factor- let's call it X- of "i" which has the maximum power in the prime factorization of "i".
if X is odd, we divide the least element of the array by 2, and if X is even, we multiply the maximum element of the array by 2. If an element becomes 0, we remove it from the array.
We can't change the order of elements of the array.
We need to find the array after all the Q queries.

How to implement it?
Thanks in advance :)

Tags prime numbers, #algorithms, data-structures

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English confusedcoder 2016-05-26 09:22:33 28
en1 English confusedcoder 2016-05-26 09:22:02 621 Initial revision (published)