# How to solve for x:$\left \lfloor{x} \right \rfloor\ - n \cdot \left \lfloor{\frac{x}{n}} \right \rfloor\ = y$

Getting solutions to questions with floor functions, like:

solve for x:$$\left \lfloor{x} \right \rfloor\ - n \cdot \left \lfloor{\frac{x}{n}} \right \rfloor\ = y$$ $$st.: \ x ∈\{0, \mathbb{R^{+}} \}, \ y ∈\mathbb{Z},\ n ∈\mathbb{Z^{+}},$$

has troubled my little brain for some time now.

This equation, of course, isn't my actual problem, but if I learn how to solve it, I can work other problems. Can anyone help? I would really appreciate any guidance about the thought process required to get to the solution.

Thanks for taking the time.

• You need to restrict $y$ to be integer. – Szeto Jul 14 '18 at 2:56
• @Szeto thank you, you're right, I meant to set it to integer type. I'll make the necessary update :) – McMath Jul 14 '18 at 2:57

Let $x = n*m + z$ where $m\in \mathbb Z$ and $0 \le z < n$

Then $[\frac xn] = m$ So $[x] - n[\frac xn] = n*m + [z] -nm = [z] = y$.

Which means to have any solutions you must have $0\le y < n$. And then the solution could by $x = n*m + z = n*m + y + w$ where $m$ can be any non-negative integer and $w$ can be any real $0\le w < 1$.

Another way of putting it, for $y < n$ then for any $k\equiv y \mod n$, $x$ can be any real number so that $k \le x < k+1$. But if $y < 0$ or $y \ge n$ there is no solution.

For example if $n = 5$ and $y= 3$ then for any $x$ can be any value in $[3,4)\cup [8,9) \cup [13,14)\cup....$

This is not a good approach.

Assume $x$ is between two consecutive multiples of $n$, i.e. $$kn<x<(k+1)n$$

Then, $$\left\lfloor\frac{x}n\right\rfloor=k$$

Thus, $$\lfloor x\rfloor=y+kn\implies x=y+kn+f$$ where $0\le f<1$.

To satisfy the assumption, $$0<y+f<n$$

If $y,n$ are fixed, as long as $y<n$, we can obtain solutions by the above method.

On the other hand, one can show that if $n<y$, there are no solutions.

As an example, for $y=1,n=3$, the integer part of $x$ can be $1,4,7,10\cdots$.

In addition, $y<0$ has no solutions for $x$.

SUMMARY:

The above steps might be quite messy. Let me summarize the results:

When $y<0$, there are no solutions.

When $n<y$, there are no solutions.

When $n=y$, there are no solutions.

When $n>y$, the solutions are $$x=y+kn+f$$ where $k$ is an arbitrary natural number or zero, $f$ is an arbitrary fractional part.