Description
Solutions
Submission
Prime Factor Visitation
🔥 FULLTIME

Alex entered a room with some fairy lights arranged in a row which each number on an elf. Alex had a list of numbers and walked through where an elf or their leader are. For each number, Alex visited the bulbs position where an elf would be visible, the prime factors of the chosen number. Whenever a number of times is stepped on, the elves determine the final state of each bulb after the numbers on the list have been passed.

For example, given four bulbs, initially states [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], where 0 means off and means on and a list of 3 numbers, numbers [3, 4, 15], the states of the bulbs after processing each number are as follows, where a bolded state means the bulb's state was flipped (As shown in Example 2).

Function Description

Complete the function lightsBulbs in the editor below. The function must return an array of integers that denote the final states of each bulb.

lightsBulbs has the following parameters:

  1. states[states[0],...states[n-1]]: an array of n integers that denote the initial states of each bulb
  2. numbers[numbers[0],...numbers[m-1]]: an array of m integers, the elements in her list

Example 1:

Input:  states = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1], numbers = [3, 8, 6]
Output: [0, 1, 1, 0, 1, 1, 0, 1, 1, 1]

Example 2:

Input:  states = [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], numbers = [3, 4, 15]
Output: [1, 0, 0, 1, 0, 0, 0, 0, 1, 1]
Explanation:
Initial state - [1, 1, 0, 0, 1, 1, 0, 1, 1, 1] numbers[0] = 3, there is one prime factor: {3}. After the states are changed, affected bulbs in bold: [1, 1, 1, 0, 1, 0, 0, 1, 0, 1] numbers[1] = 4, there is one prime factor: {2}. The states of the bulbs and the afftected bulbs are [1, 0, 1, 1, 1, 1, 0, 0, 0, 0] numbers[2] = 15, the prime factors are {3, 5}. The states of the bulbs and the affected bulbs are [1, 0, 0, 1, 1, 0, 0, 0, 1, 0] [1, 0, 0, 1, 0, 0, 0, 0, 1, 1] The final states are 1 0 0 1 0 0 0 0 1 1.
Constraints:
    1. 1 ≤ n ≤ 105
    2. 1 ≤ m ≤ 105
    3. 0 ≤ states[i] ≤ 1
    4. 1 ≤ numbers[i] ≤ 109
Testcase

Result
Case 1

input:

output: