Answer the question
In order to leave comments, you need to log in
How to understand the condition of the task?
Count the number of numbers from A to B (integer) such that the digits of the number, considered in
order from left to right, form an arithmetic or geometric progression. We
will assume that all one-digit and two-digit numbers form an arithmetic progression. To
determine whether a number fits the requirements of the task, implement the function. Also
implement a function to count the number of such numbers from 1 to n. It is forbidden to use strings
and arrays.
Answer the question
In order to leave comments, you need to log in
It seems to me that any number consisting of one digit, by condition, is a progression, i.e. it suits us. Same for doubles. Those. all one-digit and two-digit numbers that fall into the range [A, B] are suitable for us.
Consider 3-digit numbers and numbers of higher orders. In the case of a 3-digit number, for example 123 - an arithmetic progression with a difference of 1 (1, 2, 3); 124 - geometric progression with divisor 2 (1, 2, 4); 321 - arithmetic progression with difference -1 (3, 2, 1); 421 is a geometric progression with a divisor 1/2 (4, 2, 1). Those. you need to find all such numbers. Naturally, the difference can be any depending on the digits (for 3 digits from -4 to 4) and the divisor too (for 3 digits from -3 to 3). Well, this is already thinking about the decision.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question