Suppose there had been just one unfaithful husband. At the mayor’s announcement, every other wife in the village would know he was the guilty party, and his own wife, aware of no other cheating husbands, would realize that her own husband was guilty and shoot him on the first day.
If there were two unfaithful husbands, Mr. X and Mr. Y, nothing would happen on the first night. The wives with faithful husbands would know of both guilty parties, and Mrs. X and Mrs. Y could each assume that the other’s husband accounted for the mayor’s announcement. But the next day, aware that no other wife has shot her husband, Mrs. X finds herself in the position described by the preceding paragraph: She knows of Mrs. Y’s cheating husband, and the fact that Mrs. Y forbore shooting him tells her that Mrs. Y is aware of another cheating husband that she herself (Mrs. X) can’t account for. That husband can only have been her own. Mrs. Y reasons in just the same way, and both shoot their husbands on the second day.
A pattern emerges. If there were three unfaithful husbands, then nothing would happen on the first day, and that very fact would leave all three wives in the position described by the preceding paragraph. All three would shoot their husbands on the third day.
So if there are 40 unfaithful husbands in all, the village would experience 39 days of peace, and then all 40 cheating husbands would be shot by their wives on the 40th day.
(I think the principle here was introduced in “The Women of Sevitan,” a problem in Herbert Gintis’ 2000 book Game Theory Evolving.)