# When can one construct expression dividable by M from any N numbers?

You have N numbers written in one row. One needs to put any amount of the four symbols $$($$, $$)$$, $$+$$, and $$\times$$ between them in such a way that the resulting expression is divisible by $$M$$.

What are $$[N,M]$$ pairs it is always possible to do with (independently of the given sequence of numbers)?

For example, with $$N=2, M=2$$ you can always do what is asked. Indeed, if you have two numbers $$a$$ and $$b$$ and at least one is even you write $$a \times b$$, if none is even you write $$a+b$$.

• the asterix is elevated... it still means multiply right? Jun 19, 2014 at 19:22
• @kaine, yes, it does. Jun 19, 2014 at 19:23
• I may have made a mistake. The algorithm works for M=7 and M=49 but I can't show I can make a 1 in all cases. Due to the occational decreasing $N_o$ with increase $M$ I hadn't yet noticed. Jun 20, 2014 at 19:32

You can always do it if $N \ge M$. Reduce all the numbers $\pmod M$. If any are zero, put multiply signs everywhere. If not, imagine putting plus signs everywhere and keeping track of the running sum. Since there are at least $M$, either one is $0 \pmod M$ or two are the same $\pmod M$. If one of the running sums is zero, put parentheses around that addition and multiply all the rest of the numbers. If two of the running sums are the same, start after the first one and go to the end of the second. The sum of that interval will be $0 \pmod M$. Multiply by all the other numbers.
If $M$ is composite and $N$ is at least the sum of the prime factors of $M$ (counting multiplicity) you can succeed. For example, let $M=12, N=7$. We have shown that the first three elements can contribute a factor $3$ and each of the pairs of the last four can contribute a factor $2$ so we can succeed.
If $N$ is at least the sum of the prime factors of $M$ you can succeed. It may be possible to succeed with fewer-I thought I had a proof that you couldn't but it fails.
• I do not get about N<M. There is solution for N=6, M=9 for example. You just need to make first 3 numbers combination dividable by 3. Then second. Then put $\cdot$ in-between. Jun 19, 2014 at 19:38
• @klm123: yes, I realized it and updated. I don't know how to characterize the possibilities for $M$ composite. For the $N=6, M=9$ case, suppose the numbers $\pmod 3$ start $2,1,1$. You can get a multiple of $3$ from the first two, but that can't multiply a $3$ from the last $3$. In this case I can't find one that doesn't work, but it's not that simple. Jun 19, 2014 at 19:46
• @klm123: good point. So now we can say that for $M$ greater than the sum of a factorization of $N$ we can do it. I'll put that in. It might still be possible to do better. Jun 19, 2014 at 20:03