Problem 6: How Many Digits?
https://open.kattis.com/problems/howmanydigits
The number of digits of an integer can be calculated by the following formula:
is the ceiling function, which rounds a number up to the closest larger integer.
Another important property of logs: .
is only a power of 10 if or , so handle those cases separately. Otherwise:
Store the sums in a vector, and output the ceiling of that sum for each test case.
C++ has functions ceil(x)
and log10(x)
that can be used for calculations. Be careful that ceil()
returns a double, so cast to int
or long long
before printing.
Last updated