Find the number by decimal of its square root

I have a math problem consisting of two questions:

  • you can find the number N, knowing only the decimal part of its square root to accuracy (only the approximation of the decimal part, because the decimal part never ends)
  • The answer is clear? which means that we will not find two integers whose quadratic root decimal values ​​are equal (for example, the first 50).

Example:

if we have 0.4142135623730950488016887242097, can we find that this is the decimal part of the square root of 2 or 0.418286444621616658231167581 for 1234567890 The answer to the second question is quite simple, because, say, we have 50 decimal places, the number of possible squares with the square root is much larger than 10 ^ 50-1 the possible values ​​of the decimal parts, so there will be more than one answer.

I am very grateful for your help or any research work.

+6
source share
1 answer

You yourself have answered the second question. There is no unique solution.

For the first question, I do not know a quick mathematical solution, but some non-working software solutions:

  • Option A: brute force method: iterate over all integers and compare the square root of each with your number.

  • Option B: A more sophisticated brute force method that is more efficient but still slow:

    • Iterate integers from 1 to M
    • Add your decimal to each of them.
    • Take the power of two and see how close the next integer value is
    • if the next integer value is very close, take the square root of it to meet the result of the check.
    • stop once you find the correct integer
  • Option C: Caching:

    • precalculate decimal parts for all integers and save them in a HashMap.
    • Use HashMap to quickly find results.
    • Consider: since you have a very large amount of data, different decimal parts can lead to the same hash value, which violates this option.
0
source

Source: https://habr.com/ru/post/973364/


All Articles