No. of ways for $(((n \mod i) \mod j) \mod k) \mod n$

700 Views Asked by At

Consider $3$ integers, $i, j, k$ all between $1$ and $m$, both exclusive. Consider $$(((n \mod i)\mod j)\mod k)\mod n$$ where $n$ is another positive integer. Suppose the maximum value of the above expression in $L$. Find the number of ways to choose the triple $(i,j,k)$ so as to get $L$.

My try:-

Since in the end we have $\mod n$, $L$ can be $n-1$ at max. But, the thing is if it can even achieve that value! For instance, if we take both $n$, $m$ to be $4$, I checked by hit and trial that $L$ will be $1$. This got me thinking, is there a general representation for these "concatenated" mods? I've no more idea on how to proceed. Even if a hint will do. Thanks :)

2

There are 2 best solutions below

4
On

A partial result in the case $n=m$.

Take $i=j=k=p$ where $p$ is the smallest integer greater than $n/2$. Then the result is $n-p$, the greatest integer lower than $n/2$.

Furthermore, if $i \geq p$, then $n$ mod $i$ is less than $n-i \leq n-p$ so the final result is kot greater than $n-p$.

If $i < p$, then $n$ mod $i$ is not greater than $p-1$ ($n$ odd) or $p-2$ ($p$ even) ie $n-p$.

A more careful study should yield the equality cases (I think it is $i=p,n-p$ and $j,k \geq n-p$).

0
On

In every case the maximum remainder is N mod ((N/2)+1). This will be the maximum value L. Therefore L = N mod((N/2)+1)

Case 1: if N = M

Here i has to be (N/2)+1, because only that will yield remainder as L. If i has any other value, the remainder will always be less than L. Now j,k should be 1 more than (N mod i) (so that the remainder remains L) till M. Therefore j,k = (N mod i)+1 ...... M (Let this count be c) hence total number of ways = c^2

Case 2: if M > N

Subcase 1: i = (N/2)+1 will give remainder as L j,k = (N mod i)+1 ...... M (Let this count be c) Total count = c^2

Subcase 2: j = (N/2)+1 but for this to happen we have to ensure that (N mod i) = N Therefore to make N mod i = N , i = N+1 ...... M k = (N mod j)+1 ...... M (Let this count be c) Total count = (M-N)*c

Subcase 3: k = (N/2)+1 but for this to happen ((N mod i) mod j) = N, Therefore i,j = N+1 ...... M Total count = (M-N)^2

Hence total number of ways if M>N : c^2 + (M-N)*c + (M-N)^2