Solving "Number of Beautiful Pairs" with a Twist: Efficient Coprime Calculation