Answer the question
In order to leave comments, you need to log in
How to write a verbal algorithm for this task?
Task: Given a natural number k. Output the k-th digit of the sequence 149162536, in which the squares of all natural numbers are written in a row.
Thanks in advance)
Answer the question
In order to leave comments, you need to log in
The number of digits in the number is obtained by rounding up the ratio of the natural logarithm of this number to the natural logarithm of 10: ceil( ln(x) / ln(10))
Special case "one" - for it the logarithm will give 0, so we will add the length of the unit squared manually)
You can create a sequence length counter and a variable for the current number . Starting from 1, accumulate the total length of the sequence in the counter, adding the number of digits in the next square.
When the sequence hits at least the given K, the current value squared contains the digit you are looking for. The difference between the length of the dialed sequence and K will determine which digit of this square to take.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question