# Divisibility by 7 or 3

I read a question on mathematics.I have not been able to figure out the answer.

the question is

given a set $Q=\{1,2,3,4,5,6,7\}$ such that I can have a subset $L$ from this set $Q$. I have been given a number string $Y$ in such a way that I know its starting digit and the end digit.

Now the rest of the digits from second digit to the last but one digit can be have any numbers of digits from the subset $L$.

Now the question how can i decide whether $Y$ can be made divisible by $3$ or $7$.

-
I'm not sure if this is what you're looking for, but there's a pretty simple test for divisibility by 3. Namely, $3|Y \Leftrightarrow$ the sum of the digits in $Y$ is divisible by 3.So as long as you choose elements from $L$ that make $Y$ satisfy this condition, you'll be fine. There's another test for 7 though it's more complicated. Is this in the right direction or have I misunderstood? – chris May 6 '12 at 19:00
This might help: en.wikipedia.org/wiki/Divisibility_rule – user21725 May 6 '12 at 19:11
It might be useful to know that 1001 is divisible by 7 – Mark Bennet May 6 '12 at 20:53

You're given a subset $L$ of $\{{1,2,3,4,5,6,7\}}$. You're also given digits $a$ and $b$. You want to know whether there's a number $Y$ that starts with $a$, ends in $b$, has all its other digits from $L$, and is divisible by 3; then you want to know the same, but divisible by 7. If that's not the intended interpretation, maybe OP will return to let us know.
For divisibility by 3, if the number ab (by which I mean $10a+b$, not $a\times b$) is a multiple of 3, then no matter what $L$ is, you can let $Y={\rm ab}$. If the number ab is not a multiple of 3, then you can find $Y$ if and only if $L$ contains at least one of the digits 1, 2, 4, 5, 7. If $d$ is any such digit, then either adb or addb will be a multiple of 3.
Divisibility by 7 is a bit trickier. For example, if $a=3$, $b=0$, $L=\{{1\}}$, then you're out of luck, since all the numbers 30, 310, 3110, 31110, etc., leave remainder 2 on division by 7. Another example is $a=7$, $b=1$, $L=\{{7\}}$, when you're looking at the numbers 71, 771, 7771, 77771, etc. I think it shouldn't be hard to characterize the cases where there is no such $Y$, and I think that if $L$ has more than one element there are no such cases, but I leave the details as exercises.
EDIT: a couple more cases. $a=7$, $b=1$, $L=\{{3\}}$ can't be done; if $Y=7333\dots331$ then $3Y+7=22000\dots000$ which is not a multiple of 7, so $Y$ is not a multiple of 7. If $L$ contains any number other than 3 or 7, we win: 7111111, 721, 7441, 75551, and 766661 are all multiples of 7. We also win if $L=\{{3,7\}}$, since 7371 is a multiple of 7. This problem is more interesting than I thought it would be, and it might be fun for someone to do it right, that is, for every possible $a,b$ determine the sets $L$ that do, or don't, admit a value of $Y$.