You have to choose the price of items strategically for easy calculation.
The total cost price and total selling price should be divisible by both 5 and 7, so the total cost and selling price should be LCM of 5 and 7 = 35.
The number of items bought is 7 and let the price for each be 5.
Total cost price = 35
Total selling price for 5 items is 35 (same as cost price for 7 items).
Thus selling price of individual item is 7.
CP < SP
So, Gain percent = (Gain/CP)*100 = (2/5)*100 = 40%