Function for three equal consecutive digits

Write a recursive function that, given two natural numbers @n@ and @b@, returns true if and only if @n@ has three or more equal consecutive digits when expressed in base @b@.

For example, the number 44344 does not have three equal consecutive digits in base 10. By contrast, 159 in ternary is 12220, so it does have three equal consecutive digits in base 3.

Precondition

It holds 00 \le @n@ 109\le 10^9 and 22 \le @b@ 100\le 100.

Interface

C++
bool three_equal_consecutive_digits(int n, int b);
C
int three_equal_consecutive_digits(int n, int b);
Java
public static boolean three_equal_consecutive_digits(int n, int b);
Python
three_equal_consecutive_digits(n, b) # returns bool
three_equal_consecutive_digits(n: int, b: int) -> bool

Observation

You only need to submit the required procedure; your main program will be ignored.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:32:44.185Z

© Jutge.org, 2006–2026.
https://jutge.org