For a number to be divisible by $6$, it must be divisible by both $2$ and $3$. If it is divisible by $2$, it must be even, so the units digit must be $2$ or $4$. If it is divisible by $3$, the sum of its digits must be divisible by $3$.
The only one-digit positive integer that is divisible by $6$ is $6$ itself, so the number must have at least two digits.
Two-digit numbers: If the units digit is $2$, the tens digit must have remainder $1$ when divided by $3$. Hence, the tens digit must be $1$ or $4$.
If the units digit is $4$, the tens digit have remainder $2$ when divided by $3$. Hence, the tens digit must be $2$ or $5$.
Therefore, there are four two-digit numbers divisible by $6$ that can be formed using the digits $1, 2, 3, 4, 5$ without repetition. They are $12$, $24$, $42$, $54$.
Three-digit numbers: If the units digit is $2$, the sum of the hundreds digit and tens digit must have remainder $1$ when divided by $3$. Since the sum of the hundreds digit and tens digit must be at least $1 + 3 = 4$ and at most $5 + 4 = 9$, the only possibilities are that the sum of the hundreds digit and tens digit is $4$ or $7$. Since digits cannot be repeated, the only way to obtain $4$ is to use the digits $1$ and $3$ in either order, and the only way to obtain $7$ is to use the digits $3$ and $4$ in either order. Hence, there are four three-digit numbers divisible by $6$ that can be formed with the digits $1, 2, 3, 4, 5$ that have units digit $2$. They are $132$, $312$, $342$, and $432$.
If the units digit is $4$, then the sum of the hundreds digit and tens digit must have remainder $2$ when divided by $3$. Since the sum of the hundreds digit and tens digit must be at least $1 + 2 = 3$ and at most $3 + 5 = 8$, the sum of the hundreds digit and tens digit must be $5$ or $8$. Since digits cannot be repeated, the only way to obtain $5$ is to use the digits $2$ and $3$ in either order, and the only way to obtain $8$ is to use the digits $3$ and $5$ in either order. Hence, there are also four three-digit numbers divisible by $6$ that can be formed with the digits $1, 2, 3, 4, 5$ that have units digit $4$. They are $234$, $324$, $354$, $534$.
Therefore, there are a total of eight three-digit numbers divisible by $6$ that can be formed from the digits $1, 2, 3, 4, 5$ without repetition.
Four-digit numbers: If the units digit is $2$, then the sum of the thousands digit, hundreds digit, and tens digit must have remainder $1$ when divided by $3$. Since the sum of the thousands digit, hundreds digit, and tens digit must be at least $1 + 3 + 4 = 8$ and at most $3 + 4 + 5 = 12$, the sum of the thousands digit, hundreds digit, and tens digit must be $10$. Since digits cannot be repeated, the only way to obtain a sum of $10$ is to use the digits $1$, $4$, and $5$ in some order. There are $3! = 6$ such orders. Hence, there are six four-digit numbers divisible by $6$ with units digit $2$ that can be formed from the digits $1, 2, 3, 4, 5$ without repetition. They are $1452$, $1542$, $4152$, $4512$, $5142$, and $5412$.
If the units digit is $4$, the remainder of the sum of the thousands digit, hundreds digit, and tens digit must be $2$ when divided by $3$. Since the sum of the thousands digit, hundreds digit, and tens digit must be at least $1 + 2 + 3 = 6$ and at most $2 + 3 + 5 = 10$, the sum of the thousands digit, hundreds digit, and tens digit must be $8$. Since digits cannot be repeated, the only way to obtain a sum of $8$ is to use the digits $1$, $2$, and $5$ in some order. Since there are $3! = 6$ such orders, there are also six four-digit numbers that can be formed from the digits $1, 2, 3, 4, 5$ without repetition. They are $1254$, $1524$, $2154$, $2514$, $5124$, and $5214$.
Hence, there are a total of $12$ four-digit numbers divisible by $6$ that can be formed from the digits $1, 2, 3, 4, 5$ without repetition.
Five-digit numbers: The sum of the five digits $1, 2, 3, 4, 5$ is $15$, which is divisible by $3$. Hence, any five digit number formed from these digits without repetition that has units digit $2$ or $4$ is divisible by $6$. There are two ways of filling the units digit and $4!$ ways of filling the remaining digits. Hence, there are $2 \cdot 4! = 48$ five-digit numbers that can be formed with the digits $1, 2, 3, 4, 5$ without repetition.
In total, there are $4 + 8 + 12 + 48 = 72$ numbers divisible by $6$ that can be formed from the digits $1, 2, 3, 4, 5$ without repetition.
Best Answer
I'm interpreting "divisible by either $5$ or $7$" as "divisible by at least one of $5$ or $7$".
We have to build a random injective word of length $7$ over the alphabet $[9]$. Let us compute the probability $q:=1-p$ that some subsequence of five entries contains neither the letter $5$ nor the letter $7$. Such a sequence exists iff at none of the positions $3$, $4$, $5$ of the word we have one of $5$ or $7$. There are $9\cdot8\cdot 7$ equiprobable ways to fill these positions, and $7\cdot 6\cdot 5$ of them contain neither $5$ nor $7$. It follows that $q={30\over72}$, hence $p={42\over72}$, and $12p=7$.