Algorithm Analysis
The productivity of the first chubby will be cake per hour. Similarly, the productivity of the second and third chubbies in eating cake are and cake per hour. If the chubbies eat the cake simultaneously, then in one hour they will eat portion of the cake. Therefore, the entire cake can be eaten in hours.
Example
Three chubbies will eat the cake in hour.
Algorithm Implementation
Read the input data. Calculate the answer using the formula and output it.
scanf("%d %d %d", &t1, &t2, &t3); res = 1.0 / (1.0/t1 + 1.0/t2 + 1.0/t3); printf("%.2lf\n", res);
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int t1 = con.nextInt(), t2 = con.nextInt(), t3 = con.nextInt(); double res = 1.0 / (1.0/t1 + 1.0/t2 + 1.0/t3); System.out.println(res); con.close(); } }