Hi! Not sure if you are still looking for this answer but it has to do with how many calories or kilo calories are in 1 g of each of the type of nutrients.
For protein and carbs, there are 4 calories per 1 gram.
For fats, there are 9 calories per 1
gram.
From there, it is simply setting up the math:
16 grams of protein x 4 calories/1 gram = the unit gram cross cancels out leaving calories = 64 calories
Repeat for the other 2
Let me know if you still have questions!