112. Cake

 

In honor of the birth of an heir Tutti the royal chef has prepared a huge cake, that was put on the table for Three Fat Man. The first fat man can eat the cake by himself for t1 hours, second – for t2 hours, and the third – for t3 hours.

For what time can the cake be eaten simultaneously by all three fat men?

 

Input. One line contains three positive integers t1, t2 and t3, each of them is no more than 10000.

 

Output. Print the time in hours during which the cake can be eaten simultaneously by three fat men. Print the result with two digits after the decimal point.

 

Sample input

Sample output

3 3 3

1.00

 

 

SOLUTION

mathematics

 

Algorithm analysis

The productivity of the first fat man will be 1 / t1 cake per hour. Similarly, the cake eating productivity of the second and third fat man are 1 / t2 and 1 / t3 cake per hour. If the fat men eat cake at the same time, then at one oclock they will eat 1 / t1 +  1 / t2 + 1 / t3 of the cake. Therefore, the entire cake can be eaten in 1 / (1 / t1 + 1 / t2 + 1 / t3) hours.

 

Example

Three fat men will eat the cake in 1 / (1 / 3 +  1 / 3 + 1 / 3) = 1 hours.

 

Algorithm realization

Read the input data. Compute the answer using the formula and print 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 realization

 

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();

  }

}