diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index 26709b428b78..48afd8bea182 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -1,3 +1,5 @@ +import math + """ An Armstrong number is equal to the sum of its own digits each raised to the power of the number of digits. @@ -29,9 +31,8 @@ def armstrong_number(n: int) -> bool: number_of_digits = 0 temp = n # Calculation of digits of the number - while temp > 0: - number_of_digits += 1 - temp //= 10 + number_of_digits = math.floor(math.log10(temp)) + 1 + # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: