Skip to main content

Posts

Restore Sequence codechef november long challenge problem solution

 Restore Sequence codechef  november  long challenge  problem solution - Restore Sequence codechef  november  long challenge  problem solution  lets read problem statement. Alice has a very complex machine ― when fed with a sequence  A 1 , A 2 , … , A N A 1 , A 2 , … , A N , it produces a sequence  B 1 , B 2 , … , B N B 1 , B 2 , … , B N , where for each valid  i i ,  B i B i  is the largest index  j j  such that  A i A i  divides  A j A j  (since  A i A i  divides itself, such an index always exist). For example, if the machine is fed with  A = [ 2 , 6 , 5 , 3 , 4 ] A = [ 2 , 6 , 5 , 3 , 4 ] , it produces  B = [ 5 , 2 , 3 , 4 , 5 ] B = [ 5 , 2 , 3 , 4 , 5 ] . Alice gave you a sequence  B B  that was produced by the machine. Find an integer sequence  A A  such that when it is fed into the machine, then the machine produces the sequence  B B . Alice does not like huge integers, so make sure that  1 ≤ A i ≤ 4 ⋅ 10 6 1 ≤ A i ≤ 4 ⋅ 10 6  holds for each valid  i i . Input The first line of