Solving the the recurrence modular relation in the coconut problem I read in a text book about number theory that in order to find the least number n that satisfies the following conditions: 
n ≡ 1 (mod 3) 
m1 = 2(n − 1)/3 ≡ 1 (mod 3)
m2 = 2(m1 − 1)/3 ≡ 1 (mod 3)
m3 = 2(m2 − 1)/3 ≡ 1 (mod 3) 
The author just substituted m3 with n and then solved for n:  
m3= 8n/27−38/27 ≡ 1(mod3)
8n ≡ 65(mod 81) 
n ≡ 8−1 ·65 ≡ 71·65 ≡ 79(mod 81), and then the smallest solution is 79.  
I understand that what he did will guarantee him the last condition and the fact that n is a natural number. what I don't understand is why would this imply that m1 and m2 are natural numbers or that they are congruent to 1(mod3). Again, I understand that the answer is correct after checking but why would it be true without checking?   p.s: This relation came from the 3-sailors version of the coconut problem.
 A: All right, the comments don't have enough space, let me tackle this as an answer. To save on phone typing, I'm going to use $a,b,c,d$ instead of the $n$ and $m$s.
First, let's fully state the standard puzzle. We have three stranded pirates, Q, R, and S. During the day they gathered a bunch of coconuts to keep them alive, but they were too tired to sort them into personal stashes.
During the night, Q wakes up. He thinks "I'll just take my share... now. And in the morning." He divvies the coconuts into three equal piles. There's one left over, which he tosses to a nearby monkey. He takes and hides one of the piles, then puts the other two piles together into one pile.
Later, R wakes up and does the same thing. Again there's one extra after counting into three piles, and he tosses it to (presumably the same) nearby monkey. S wakes up later and does the same thing, with the monkey getting another coconut.
After daybreak, the three go to the rather-suspiciously-smaller pile. They sort the coconuts into three piles, one for each of them, and, one last time there's an extra, which the monkey gets.
Question: What is the smallest number of coconuts they could have begun with?

We have a lot of constraints if you really think about it:
$$
\begin{align}
& a \equiv b \equiv c \equiv d \equiv 1 \pmod 3 \\
& b = \textstyle{2 \over 3} (a-1) \\
& c = \textstyle{2 \over 3} (b-1) \\
& d = \textstyle{2 \over 3} (c-1) 
\end{align}
$$
Here, $a$ is the solution, and $b,c,d$ are the sizes of the smaller stacks before dividing.
All of these constraints must be fulfilled in order to get an answer. The first line of four constraints is needed because in each of the four splits, there was a coconut left over after making three equal piles. The three equalities describe the splitting process: each time, one coconut gets tossed away, and $\frac23$ of the rest end up in the leftover pile.
As an additional constraint, $a,b,c,d$ must all be positive integers.
(Much of our talking past one another in the comments can be simplified to these constraints. We assume $b \equiv 1 \pmod 3$, and $c \in \mathbb{N}$, and so forth, because the problem requires those assumptions to be true.)
Perhaps it's more intuitive to work in reverse. In the morning, the pile has $d$ coconuts, and $d = 3f+1$ for some $f$. Going backward in time, S multiplies the pile by $\frac32$, then adds $1$, to get pile $c = \frac32 d +1$.
There's an extra constraint/information tidbit here: since we must have integers, $d$ must be divisible by $2$. Since R and Q performed the same process (still in reverse), $c$ and $b$ must also be even.
Because of the constraint to integers, we know from the equalities that $3 \mid 2a-2$, and the same for $b,c$. Conveniently, this also causes the constraint of $a,b,c \equiv 1 \pmod 3$ to be true, as
$$3 \mid 2a-2 \iff 2a-2 \equiv 0 \pmod 3 \iff a \equiv 1 \pmod 3$$
Continuing with our reverse time, R takes pile $c$ and forms $b = \frac32 c+1 = \frac94 d + \frac52$. Then Q takes that pile and forms
$$ a = \frac{3}{2} b + 1 = \frac{27d + 38}{8}$$
which we recognize as quite similar to part of the original solution. And in fact we can convert this to a modular congruence by assuming $a$ can take multiple values:
$$27d \equiv -38 \pmod {8} \equiv 2 \pmod 8 \iff d \equiv 6 \pmod 8$$
But wait! This isn't the same congruence we had earlier. What did we forget? Well, we never did satisfy the constraint that $d \equiv 1 \pmod 3$. (The above congruence fulfills $d$ being even.) So we have a system of congruences:
$$
\begin{cases}
d & \equiv 6 \pmod 8 \\
d & \equiv 1 \pmod 3
\end{cases}
$$
Solving gives us $d \equiv 22 \pmod 24$. From $d=22$, you can calculate (in reverse) to find $a=79$.
This fulfills all of the constraints we listed, and gives an answer that aligns with them all.
Interesting side note: almost every congruence in this solution is $-2 \pmod k$, for various values of $k$. Also true in the original solution.
