Connection Status:
Competition Arena > MooresLaw
SRM 287 · 2006-02-04 · by misof · Math, Search
Class Name: MooresLaw
Return Type: double
Method Name: shortestComputationTime
Arg Types: (int)
Problem Statement

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.

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
4)
1
Returns: 1.0

Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class MooresLaw with a public method double shortestComputationTime(int years) · 44 test cases · 2 s / 256 MB per case

Submitting as anonymous