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
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
14
Returns: 6.2044816339207705
The example from the problem statement.
3
Returns: 2.870893001916099
47
Returns: 8.82533252835082
123
Returns: 10.907221008843223
1
Returns: 1.0
2
Returns: 2.0
4
Returns: 3.4934492508343644
5
Returns: 3.976341393165408
15
Returns: 6.3537851442471425
23
Returns: 7.278792184919884
37
Returns: 8.307629299277789
59
Returns: 9.317413824877127
145
Returns: 11.263312885856767
172
Returns: 11.63284638288751
578
Returns: 14.255837774585384
792
Returns: 14.937484180953778
2341
Returns: 17.282813079502382
7985
Returns: 19.938064289282256
22145
Returns: 22.145489315993384
19728
Returns: 21.895384877438623
74470
Returns: 24.77000685648385
135498
Returns: 26.065317298034948
603785
Returns: 29.29896233651874
2547800
Returns: 32.414680152491634
5000000
Returns: 33.87369424715167
12345678
Returns: 35.82970335003532
87654321
Returns: 40.0714320647176
123456789
Returns: 40.812595650125076
456789012
Returns: 43.643878310398875
912121212
Returns: 45.14042472529701
992134572
Returns: 45.322390118570624
999912360
Returns: 45.33928886681244
999990989
Returns: 45.339459031538375
999999947
Returns: 45.3394784171195
999999997
Returns: 45.339478525321624
999999998
Returns: 45.33947852748567
999999999
Returns: 45.33947852964971
1000000000
Returns: 45.339478531813754
1000000000
Returns: 45.339478531813754
1
Returns: 1.0
999999999
Returns: 45.33947852964971
2
Returns: 2.0
999999997
Returns: 45.339478525321624
14
Returns: 6.2044816339207705