TopCoder problem "MooresLaw" used in SRM 287 (Division I Level Two)



Problem Statement

    

Moore's law is a well-known prediction of the growth of computing power over time. This is the formulation we will use in this problem: The speed of new computers grows exponentially and doubles every 18 months. In this problem we will assume that reality precisely obeys this law.

Suppose that you have a hard computational task that would take 14 years to complete on a current computer. Surprisingly, starting its computation as soon as possible is not the best you can do. A better solution: Wait for 18 months and buy a better computer. It will be twice as fast, and therefore solve the task in 7 years. You would have the result 8.5 years from now. In the best possible solution you should wait for slightly over 4 years. The computer you'll be able to buy then will solve the task in approximately 2.2 years, giving a total of 6.2 years.

You have a computational task you want to solve as quickly as possible. You will be given an int years giving the number of years it would take on a computer bought today. Return a double giving the least number of years in which you will have the result of the task if you use the above approach.

 

Definition

    
Class:MooresLaw
Method:shortestComputationTime
Parameters:int
Returns:double
Method signature:double shortestComputationTime(int years)
(be sure your method is public)
    
 

Notes

-Your return value must have an absolute or relative error less than 1e-9.
-The computation speed growth is a continuous exponential function satisfying the property from the problem statement.
 

Constraints

-years will be between 1 and 1,000,000,000, inclusive.
 

Examples

0)
    
14
Returns: 6.2044816339207705
The example from the problem statement.
1)
    
3
Returns: 2.870893001916099
2)
    
47
Returns: 8.82533252835082
3)
    
123
Returns: 10.907221008843223

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=5973

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9808&pm=5973

Writer:

misof

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math, Search