Task:
A new metro station will soon open in Baku. An escalator on the subway consists of n steps, numbered with integers from 1 to n. On the steps with numbers that are multiples of ten, as well as on the first and last steps, write their numbers. When writing a number, the same amount of ink goes to each recorded digit.
To calculate the required amount of paint, you need to know how many numbers will be written. Write a program that determines how many total numbers will be used in the numbers of the signed steps.
Input data:
One integer n (1 ≤ n ≤ 10 ^ 18) is the number of escalator steps.
Output:
Output the total number of digits in the numbers of the signed steps.
It is necessary to solve only with the help of formulas and functions (without using conditional operators, cycles, etc.)
Here are the sketches of the code where I calculated the number of numbers for painting and the number of digits in the final number, there are many ideas, but all of them are not implemented without cycles in my understanding.
#include <iostream> #include <cmath> using namespace std; int main() { long long n; long double num, numz; cin >> n; num = ceil(n / 10.0); numz = ceil(log10(n)); return 0; } The problem is that I cannot understand how without a cycle to take into account the fact that the number of digits in a number changes each digit and count their sum. I would be grateful for any help and tips.
n / 10.0- a characteristic case of a bomb of implicit conversions. The fact is thatdoublecan store whole numbers without loss only up to 2 ^ 53, andncan be larger. In general, the sum of the numbers is considered easy, it is enough to make a digit sign. - VTT