Let x represent the number of visits it will take for the cost of the two gyms to be the same.
Gym A has a $56 joining fee with $3 per visit. This means that the cost of x visits of gym A would be
3 * x + 56
= 3x + 56
Gym B has a $30 joining fee with a $5 per visit. This means that the cost of x visits of gym B would be
5 * x + 30
= 5x + 30
For both costs to be the same, it means that
3x + 56 = 5x + 30
5x - 3x = 56 - 30
2x = 26
x = 26/2
x = 13
After 13 visits, the cost of the two gyms would be the same