Solution:
Suppose if there is just one unfaithful husband, then his wife will kill her husband as she must be knowing that all other men are faithful but the queen declared that one of them all is unfaithful.
If there are two unfaithful husbands, then both their wives will believe there is just one unfaithful husband, that too the other one whom she knows. Thus both of them will expect the above case to happen at midnight. But when no one is shot, they will realize that there are two unfaithful husbands and since they know about everyone, they will know that the other unfaithful man is their own husband on the next day.
If there are three unfaithful husbands, each of their wives will be knowing about two other unfaithful men so they will be expecting the above case and will be waiting for the gunshots on the second day. When that does not happens, they will realize that there are more than two and since they all will know about the rest, they will realize that their own husband is unfaithful and they will kill him on the third day.
Thus if we talk about general terms and suppose that there are n unfaithful husbands, their wives will believe that there is n-1 unfaithful husbands and will expect the gunshot on n-1 day. When they don’t hear that, they will realize their own husband is the nth.