Oxygen (and the other BrINClHOF atoms) are diatomic only when you're talking about their elemental form. When these molecules form compounds, they are not necessarily diatomic. So, to find the number of oxygen atoms in your compound, you would divide by the molar mass of an oxygen atom (16g/mol) and not the molar mass of an oxygen molecule (32g/mol).