Taavas and saddas

is this approach correct considering 4 and 7 as pseudo binary system


is it a slow approach?

your approach passes all the test cases. so this approach is fine