Pyrotechnics deals 4 damage divided as you choose among any number of targets.
If an effect creates a copy of Pyrotechnics, the number of targets and division of damage can’t be changed. The effect that creates the copy may allow you to change the targets, however.
If some but not all of Pyrotechnics’s targets become illegal, you can’t change the division of damage. Damage that would have been dealt to illegal targets simply isn’t dealt.
You choose how the damage is divided as you cast the spell, not as it resolves. Each target must be assigned at least 1 damage.