Statistics

Problem Statement for "MooresLaw"

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

  1. 14

    Returns: 6.2044816339207705

    The example from the problem statement.

  2. 3

    Returns: 2.870893001916099

  3. 47

    Returns: 8.82533252835082

  4. 123

    Returns: 10.907221008843223

  5. 1

    Returns: 1.0

  6. 2

    Returns: 2.0

  7. 4

    Returns: 3.4934492508343644

  8. 5

    Returns: 3.976341393165408

  9. 15

    Returns: 6.3537851442471425

  10. 23

    Returns: 7.278792184919884

  11. 37

    Returns: 8.307629299277789

  12. 59

    Returns: 9.317413824877127

  13. 145

    Returns: 11.263312885856767

  14. 172

    Returns: 11.63284638288751

  15. 578

    Returns: 14.255837774585384

  16. 792

    Returns: 14.937484180953778

  17. 2341

    Returns: 17.282813079502382

  18. 7985

    Returns: 19.938064289282256

  19. 22145

    Returns: 22.145489315993384

  20. 19728

    Returns: 21.895384877438623

  21. 74470

    Returns: 24.77000685648385

  22. 135498

    Returns: 26.065317298034948

  23. 603785

    Returns: 29.29896233651874

  24. 2547800

    Returns: 32.414680152491634

  25. 5000000

    Returns: 33.87369424715167

  26. 12345678

    Returns: 35.82970335003532

  27. 87654321

    Returns: 40.0714320647176

  28. 123456789

    Returns: 40.812595650125076

  29. 456789012

    Returns: 43.643878310398875

  30. 912121212

    Returns: 45.14042472529701

  31. 992134572

    Returns: 45.322390118570624

  32. 999912360

    Returns: 45.33928886681244

  33. 999990989

    Returns: 45.339459031538375

  34. 999999947

    Returns: 45.3394784171195

  35. 999999997

    Returns: 45.339478525321624

  36. 999999998

    Returns: 45.33947852748567

  37. 999999999

    Returns: 45.33947852964971

  38. 1000000000

    Returns: 45.339478531813754

  39. 1000000000

    Returns: 45.339478531813754

  40. 1

    Returns: 1.0

  41. 999999999

    Returns: 45.33947852964971

  42. 2

    Returns: 2.0

  43. 999999997

    Returns: 45.339478525321624

  44. 14

    Returns: 6.2044816339207705


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: