What is the remainder when the 123,456,789th Fibonacci number is divided by 4?
Hello, this is 108Hassium.
The weekly updates on note that I started last September have reached their first anniversary, and this is my 55th article.
Since 55 is a Fibonacci number, I will talk about Fibonacci numbers in this article.
What is the remainder when the 123,456,789th Fibonacci number is divided by 4?
I will try to solve the problem in the title.
First, I will abbreviate the remainder of the Fibonacci sequence divided by $${m}$$ as $${F_m(n)}$$.
Since the remainder of $${F(n+2)}$$ divided by 4 is determined by the combination of the remainders of $${F(n+1)}$$ and $${F(n)}$$ divided by 4, I will list the pairs of $${F_4(n)}$$ and $${F_4(n+1)}$$ in order.
$${(F_4(0),F_4(1))=(0,1)}$$
$${(F_4(1),F_4(2))=(1,1)}$$
$${(F_4(2),F_4(3))=(1,2)}$$
$${(F_4(3),F_4(4))=(2,3)}$$
$${(F_4(4),F_4(5))=(3,1)}$$
$${(F_4(5),F_4(6))=(1,0)}$$
$${(F_4(6),F_4(7))=(0,1)}$$
Since we have reached the same combination (0,1) as the initial values, we can see that $${F_4(n)}$$ is a periodic sequence with a period of 6, repeating the sequence "0, 1, 1, 2, 3, 1".
The fact that $${F_4(n)}$$ has a period of 6 means that we can calculate $${F_4(n)}$$ by finding the remainder of $${n}$$ divided by 6.
The remainder of 123,456,789 divided by 6 is 3, so the remainder when the 123,456,789th Fibonacci number is divided by 4 is equal to $${F_4(3)}$$, which is 2.
By the way, what happens if we extend this problem to the remainder when divided by a number other than 4?
For example, if we want to find the remainder when divided by 10 (the last digit), how would the difficulty change?
In this case, we can investigate the period of $${F_{10}(n)}$$ just as we did before, but it seems that the period of $${F_m(n)}$$ is a concept known as the "Pisano period," which is famous enough to have its own Wikipedia page (though there is no Japanese version).
The period of $${F_m(n)}$$ is denoted as $${{\pi(m)}}$$ (which apparently has nothing to do with pi), and according to Wikipedia, $${{\pi(10)=60}}$$.
Since 123456789 = 60 × 2057613 + 9, $${{F_{10}(123456789)=F_{10}(9)=4}}$$.
What is the remainder when F(F(F(F(123)))) is divided by 33?
Everything discussed so far is just an introduction to present the Fibonacci sequence period and the Pisano period.
From here on, I will talk about a strange property regarding Fibonacci numbers that I discovered a long time ago. (I have barely looked into any prior research.)
First, the Pisano period can be calculated with code like the following.
void setup(){
println(p(10));
}
int p(int m){
int f,pf,ppf,a;
pf=1;
f=1;
for(a=1;!(pf==0&&f==1);a++){
ppf=pf;
pf=f;
f=(pf+ppf)%m;
}
return a;
}※Language is Processing
※The value of p(1) cannot be calculated correctly
When you run this, for example, the value 60, which is $${{\pi(10)}}$$, will be output.
Now, the remainder when $${{F(F(F(F(123))))}}$$ is divided by 33 can be calculated using the following procedure.
First, since $${{\pi(33)=40}}$$, we know that to find the remainder when $${{F(F(F(F(n))))}}$$ is divided by 33, we just need to find the remainder when $${{F(F(F(n)))}}$$ is divided by 40.
Next, since $${{\pi(40)=60}}$$, we know that to find the remainder when $${{F(F(F(n)))}}$$ is divided by 40, we just need to find the remainder when $${{F(F(n))}}$$ is divided by 60.
Next, since $${{\pi(60)=120}}$$, we know that to find the remainder when $${{F(F(n))}}$$ is divided by 60, we just need to find the remainder when $${{F(n)}}$$ is divided by 120.
Next, since $${{\pi(120)=120}}$$, we know that to find the remainder when $${{F(n)}}$$ is divided by 120, we just need to find the remainder when $${{n}}$$ is divided by 120.
From the above,
$${{F_{33}(F(F(F(123))))\\=F_{33}(F_{40}(F_{60}(F_{120}(123))))\\=F_{33}(F_{40}(F_{60}(3)))\\=F_{33}(F_{40}(2))\\=F_{33}(1)\\=1}} $$
can be calculated.
By the way, the values 40, 60, and 120 that appeared during the calculation correspond to $${{\pi(33)}}$$, $${{\pi(\pi(33))}}$$, and $${{\pi(\pi(\pi(33)))}}$$, and when expressed as a sequence,
$${{\begin{cases}a_0=33\\a_{n+1}=\pi(a_n)\end{cases}}}$$
...can be expressed by this recurrence relation.
Since $${{a_3=a_4=120}}$$ in this sequence, only 120 will continue to appear from that point on.
Now, if we change the initial values and calculate this sequence, it becomes as follows.
1→1
2→3→8→12→24→24
3→8→12→24→24
4→6→24→24
5→20→60→120→120
6→24→24
7→16→24→24
8→12→24→24
9→24→24
10→60→120→120
It seems that for initial values other than these, $${a_n}$$ also converges to some value.
Question 1-1:Is it possible for $${a_n}$$ to diverge to infinity?
Question 1-2:Is it possible for $${a_n}$$ to converge to a periodic sequence with a period of 2 or more?
By the way, among natural numbers up to 500,000, the following 7 numbers satisfy $${n=\pi(n)}$$.
1
24
120
600
3000
15000
75000
375000
Question 2-1:Does $${24×5^n=\pi(24×5^n)}$$ hold for all non-negative integers $${n}$$?
Question 2-2:Are the only numbers $${m}$$ that satisfy $${m=\pi(m)}$$ the numbers that can be expressed in the form $${m=24×5^n}$$ and 1?
By the way, the Collatz conjecture is famous when it comes to problems asking whether a certain sequence converges to a constant result regardless of the initial value.
Speaking of the Collatz conjecture, it is famous (perhaps) that the number of terms until reaching 1 varies greatly depending on the initial value, but the number of terms until $${a_n}$$ reaches a fixed point does not seem to fluctuate as violently as the Collatz sequence.

Hereinafter, let $${\rho(m)}$$ be the minimum $${m}$$ such that $${a_{m}=a_{m+1}}$$ when $${a_0=n}$$.
Question 3-1:For any arbitrarily large $${n}$$, does there exist an $${m}$$ that satisfies $${n<\rho(m)}$$?
I investigated $${m}$$ for which the maximum value of $${\rho(m)}$$ is updated with initial values of 500,000 or less, and the results were as follows.
$${\rho(2)=4}$$
$${\rho(127)=6}$$
$${\rho(509)=7}$$
$${\rho(1019)=8}$$
$${\rho(2039)=9}$$
$${\rho(4079)=10}$$
$${\rho(16384)=11}$$
$${\rho(32768)=12}$$
$${\rho(65536)=13}$$
$${\rho(131072)=14}$$
$${\rho(262144)=15}$$
Looking closely, from the 7th line onwards, the arguments on the left side are all powers of 2.
Question 3-2: Do values of $${m}$$ that update the maximum value of $${\rho(m)}$$ only become powers of 2 from a certain point onwards?
I also calculated $${\rho(n)}$$ for powers of 2 smaller than 16384.
$${\rho(2)=4}$$
$${\rho(4)=2}$$
$${\rho(8)=2}$$
$${\rho(16)=1}$$
$${\rho(32)=2}$$
$${\rho(64)=3}$$
$${\rho(128)=4}$$
$${\rho(256)=5}$$
$${\rho(512)=6}$$
$${\rho(1024)=7}$$
$${\rho(2048)=8}$$
$${\rho(4096)=9}$$
$${\rho(8192)=10}$$
The first three are irregular, but after that, they increase by 1 each time.
Question 3-3: Does $${\rho(2^{n+3})=n}$$ hold for all natural numbers $${n}$$?
If Question 3-2 is resolved affirmatively, Question 3-1 will also be resolved automatically.
Incidentally, the Collatz sequence has a similar property where, if you use a power of 2 as the initial value, the number of terms to reach 1 increases by 1 for every increment in the exponent. However, that property is almost obvious from the definition, so it is not as interesting as Question 3-3.
Also, as a side note, among the values 2, 127, 509, 1019, 2039, and 4079 that appear before the powers of 2, the four values excluding the first two can be expressed as follows.
$${509=512-3=2^9-2^1-1}$$
$${1019=1024-5=2^{10}-2^2-1}$$
$${2039=2048-9=2^{11}-2^3-1}$$
$${4079=4096-17=2^{12}-2^4-1}$$
I thought that perhaps $${{\rho(2^{n+8}-2^n-1)=n+6}}$$ might hold, but unfortunately, $${{\rho(2^{13}-2^5-1)=3}}$$ and it did not hold.
What is the remainder when L(L(L(L(123)))) is divided by 33?
The terms of the following sequence are called Lucas numbers.
$${\begin{cases}L(0)=2\\L(1)=1\\L(n+2)=L(n+1)+L(n)\end{cases}}$$
* Unlike the Fibonacci sequence, the sequence itself does not seem to be called the Lucas sequence.
Also, let $${{\pi_L(n)}}$$ denote the period of the sequence of Lucas numbers modulo $${n}$$.
The value of $${{\pi_L(n)}}$$ differs from $${{\pi(n)}}$$ depending on $${n}$$, and the first 10 values of $${n}$$ for which $${{\pi(n)\neq\pi_L(n)}}$$ and their corresponding $${{\pi(n)}}$$ and $${{\pi_L(n)}}$$ values are as follows.

As you can see at a glance, all values of $${n}$$ are multiples of 5.
Apparently, this is a known property and is mentioned in the comments section of the OEIS.
Now, since the period changes when it is a multiple of 5, the calculation of the remainder when $${L(L(L(L(123))))}$$ is divided by 33 seems likely to follow a different path from the Fibonacci case halfway through.
$${{\pi_L(33)=40}}$$, the value of $${{\pi_L(\pi_L(33))}}$$ is 12 instead of 60, and $${{\pi_L(\pi_L(\pi_L(33)))=24}}$$, $${{\pi_L(\pi_L(\pi_L(\pi_L(33))))=24}}$$.
The remainder when 123 is divided by 24 is 3, the remainder when $${L(123)}$$ is divided by 24 is 3, the remainder when $${L(L(123))}$$ is divided by 12 is 3, the remainder when $${L(L(L(123)))}$$ is divided by 40 is 3, and thus we find that the remainder when $${L(L(L(L(123))))}$$ is divided by 33 is 3.
Hereinafter, similar to $${a_n}$$ for Fibonacci numbers, we define the sequence $${b_n}$$ as $${b_{n+1}=\pi_L(b_n)}$$.
While $${a_n}$$ had many (likely infinitely many) fixed points, for $${b_n}$$, only two fixed points were found below 500,000.
Question 4:Are 1 and 24 the only values of $${n}$$ for which $${n=\pi_L(n)}$$ holds?
By the way, Lucas numbers are just Fibonacci numbers with different initial values, but it is possible to create sequences with different initial values other than Lucas numbers.
What happens to the period of such sequences modulo $${n}$$?
Although there are an infinite number of combinations for the initial values, the number of combinations of remainders when the initial values are divided by $${n}$$ is only $${n^2}$$, so the number of loops must be finite.
Therefore, I wrote a program to investigate.
void setup(){
int x,px,ppx,n=0;
int[][] list=new int[10][10];
for(int a=0;a<10;a++){
for(int b=0;b<10;b++){
list[a][b]=0;
}
}
for(int a=0;a<10;a++){
for(int b=0;b<10;b++){
if(list[a][b]==0){
n++;
px=a;
x=b;
print(a+",");
for(int c=0;!(0<c&&px==a&&x==b);c++){
print(x+",");
ppx=px;
px=x;
x=(px+ppx)%10;
list[px][x]=n;
}
println();
}
}
}
println("loop;"+n);
}This is a program that enumerates all loops of remainders when dividing a Fibonacci sequence with different initial values by 10.
The execution results are as follows.
0,0,
0,1,1,2,3,5,8,3,1,4,5,9,4,3,7,0,7,7,4,1,5,6,1,7,8,5,3,8,1,9,0,9,9,8,7,5,2,7,9,6,5,1,6,7,3,0,3,3,6,9,5,4,9,3,2,5,7,2,9,1,0,
0,2,2,4,6,0,6,6,2,8,0,8,8,6,4,0,4,4,8,2,0,
0,5,5,0,
1,3,4,7,1,8,9,7,6,3,9,2,1,
2,6,8,4,2,
loop;6
The long sequence on the second line is the 60-period sequence of the standard Fibonacci sequence divided by 10, and there are also loops with periods of 20, 3, 12, and 4, for a total of 6 loops.
I rewrote the program slightly to output the results as an image.

The horizontal axis represents the remainder of the 0th initial value divided by 10, the vertical axis represents the remainder of the 1st initial value divided by 10, and values included in the same loop are painted with the same color.
Changing the divisor results in something like this.










I thought it wouldn't make a very interesting pattern if I increased the size, but I discovered one that was clearly different.

Only this part has a distinctly linear pattern.
What is the remainder when P(P(P(P(123)))) is divided by 33?
The terms of the following sequence are called Pell numbers.
$${\begin{cases}P(0)=0\\P(1)=1\\P(n+2)=2P(n+1)+P(n)\end{cases}}$$
Also, we will denote the period of the remainder when Pell numbers are divided by $${n}$$ as $${\pi_P(n)}$$.
Since $${\pi_P(33)=24}$$, $${\pi_P(\pi_P(33))=8}$$, and $${\pi_P(\pi_P(\pi_P(33)))=8}$$, the remainder when 123 is divided by 8 is 3, the remainder when $${P(123)}$$ is divided by 8 is 5, the remainder when $${P(P(123))}$$ is divided by 8 is 5, the remainder when $${P(P(P(123)))}$$ is divided by 24 is 5, therefore the remainder when $${P(P(P(P(123))))}$$ is divided by 33 is 29.
When I calculated $${n}$$ such that $${n=\pi_P(n)}$$ holds, powers of 2 appeared: 2, 4, 8, 16, 32...
Question 5-1:Does $${\pi_P(2^n)=2^n}$$ hold for all natural numbers $${n}$$?
Question 5-2:Are powers of 2 the only $${n}$$ for which $${\pi_P(n)=n}$$ holds?
By the way, the sequences of Fibonacci numbers, Lucas numbers, and Pell numbers all belong to a group of sequences called "Lucas sequences".
Lucas sequences are two sequences defined as follows using two integers $${p,q}$$.
$${\begin{cases}U_{p,q}(0)=0\\U_{p,q}(1)=1\\U_{p,q}(n+2)=pU_{p,q}(n+1)-qU_{p,q}(n)\end{cases}}$$
$${\begin{cases}V_{p,q}(0)=2\\V_{p,q}(1)=p\\V_{p,q}(n+2)=pV_{p,q}(n+1)-qV_{p,q}(n)\end{cases}}$$
*To match the notation used in the article so far, I am using a different notation than the definition found on Wikipedia.
For Lucas sequences, we can define the "period of the remainder when divided by $${n}$$" and the "sequence obtained by iteratively calculating the period of the remainder when divided by $${n}$$" just as we did before, so we define them as follows.
Let $${\pi_{U_{p,q}}(m)}$$ be the period of the sequence of remainders when $${U_{p,q}(n)}$$ is divided by $${m}$$.
Let $${\pi_{V_{p,q}}(m)}$$ be the period of the sequence of remainders when $${V_{p,q}(n)}$$ is divided by $${m}$$.
$${A_{p,q}(n+1)=\pi_{U_{p,q}}(A_{p,q}(n))}$$
$${B_{p,q}(n+1)=\pi_{U_{p,q}}(B_{p,q}(n))}$$
Question 6-1:What are the conditions for $${p,q}$$ such that $${A_{p,q}(n)}$$ or $${B_{p,q}(n)}$$ diverges to infinity?
Question 6-2:What are the conditions for p and q such that either A_{p,q}(n) or B_{p,q}(n) converges to a loop of period 2 or greater?
Question 6-3:How does the number of terms until A_{p,q}(n) and B_{p,q}(n) converge to a fixed point change depending on p and q?
I have not yet been able to find any p, q such that A_{p,q}(n) or B_{p,q}(n) diverges to infinity on my own, but for a period-2 loop, I have found examples like 2→3→2 in A_{3,-1}(n). (Examples of period 3 or greater have not been discovered yet.)
Question 6-3 is quite ambiguous as a problem to begin with, but I feel that A_{3,-1}(n) often has initial values where convergence is slightly slower than in the case of Fibonacci numbers.

This is a side note, but as a type of sequence that extends the Fibonacci sequence, there is also the Tribonacci sequence, separate from the Lucas numbers.
{\begin{cases}T(0)=0\\T(1)=0\\T(2)=1\\T(n+3)=T(n+2)+T(n+1)+T(n)\end{cases}}
I also investigated the period of the remainder π_T(n) and its iterative calculation for the Tribonacci sequence, but it seems that π_T(π_T(π_T(…π_T(n)…))) diverges to infinity for most n.
Originally, I intended to touch upon the problem "What is the remainder when T(T(T(T(123)))) is divided by 33?" in this article, but I gave up because I could not calculate it.
Question 7:What is the remainder when T(T(T(T(123)))) is divided by 33?
Bonus
Since the topic of iterative calculation of the Fibonacci sequence came up, I extended the general term of the Fibonacci sequence to complex numbers and drew a fractal figure.

In short, it is the Julia set of \frac{\phi^z-(1-\phi)^z}{\sqrt{5}}.
Note that the (1-\phi)^z part is
{(1-\phi)^z\\=e^{z\text{ln}(1-\phi)}\\=e^{z(\text{ln}(-1)+\text{ln}(\phi-1))}\\=e^{z(i\pi+\text{ln}(\phi-1))}}
...I transformed and calculated it like this.
However, since the value of ln(-1) is not uniquely determined in the first place, I also drew versions where the value of ln(-1) was changed.



