Interesting facts about Fibonacci numbers
We know Fibonacci number, Fn = Fn-1 + Fn-2.
First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, …. .
Here are some interesting facts about Fibonacci number :
1. Pattern in Last digits of Fibonacci numbers :
Last digits of first few Fibonacci Numbers are :
0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, ...
The series of last digits repeats with a cycle length of 60 (Refer this for explanations of this result).
C
// C program to demonstrate that sequence of last // digits of Fibonacci numbers repeats after 60. #include<stdio.h> #define max 100 int main() { long long int arr[max]; arr[0] = 0; arr[1] = 1; // storing Fibonacci numbers for (int i = 2; i < max; i++) arr[i] = arr[i-1] + arr[i-2]; // Traversing through store numbers for (int i = 1; i < max - 1; i++) { // Since first two number are 0 and 1 // so, if any two consecutive number encounter 0 and 1 // at their unit place, then it clearly means that // number is repeating/ since we just have to find // the sum of previous two number if ((arr[i] % 10 == 0) && (arr[i+1] % 10 == 1)) break; } printf("Sequence is repeating after index %d", i); } |
Java
// Java program to demonstrate that sequence of last // digits of Fibonacci numbers repeats after 60. class GFG{ static int max=100; public static void main(String[] args) { long[] arr=new long[max]; arr[0] = 0; arr[1] = 1; int i=0; // storing Fibonacci numbers for (i = 2; i < max; i++) arr[i] = arr[i-1] + arr[i-2]; // Traversing through store numbers for (i = 1; i < max - 1; i++) { // Since first two number are 0 and 1 // so, if any two consecutive number encounter 0 and 1 // at their unit place, then it clearly means that // number is repeating/ since we just have to find // the sum of previous two number if ((arr[i] % 10 == 0) && (arr[i+1] % 10 == 1)) break; } System.out.println("Sequence is repeating after index "+i); } } // This code is conributed by mits |
Python3
# Python3 program to demonstrate that sequence of last # digits of Fibonacci numbers repeats after 60. if __name__=='__main__': max = 100 arr = [0 for i in range(max)] arr[0] = 0 arr[1] = 1 # storing Fibonacci numbers for i in range(2, max): arr[i] = arr[i - 1] + arr[i - 2] # Traversing through store numbers for i in range(1, max - 1): # Since first two number are 0 and 1 # so, if any two consecutive number encounter 0 and 1 # at their unit place, then it clearly means that # number is repeating/ since we just have to find # the sum of previous two number if((arr[i] % 10 == 0) and (arr[i + 1] % 10 == 1)): break print("Sequence is repeating after index", i) # This code is contributed by # Sanjit_Prasad |
C#
// C# program to demonstrate that sequence of last // digits of Fibonacci numbers repeats after 60. class GFG{ static int max=100; public static void Main() { long[] arr=new long[max]; arr[0] = 0; arr[1] = 1; int i=0; // storing Fibonacci numbers for (i = 2; i < max; i++) arr[i] = arr[i-1] + arr[i-2]; // Traversing through store numbers for (i = 1; i < max - 1; i++) { // Since first two number are 0 and 1 // so, if any two consecutive number encounter 0 and 1 // at their unit place, then it clearly means that // number is repeating/ since we just have to find // the sum of previous two number if ((arr[i] % 10 == 0) && (arr[i+1] % 10 == 1)) break; } System.Console.WriteLine("Sequence is repeating after index "+i); } } // This code is conributed by mits |
PHP
<?php // php program to demonstrate that // sequence of last digits of // Fibonacci numbers repeats after // 60. global $MAX=100 $arr[0] = 0; $arr[1] = 1; // storing Fibonacci numbers for ($i = 2; $i < 100; $i++) $arr[$i] = $arr[$i-1] + $arr[$i-2]; // Traversing through store // numbers for ($i = 1; $i <100 - 1; $i++) { // Since first two number are // 0 and 1 so, if any two // consecutive number encounter // 0 and 1 at their unit place, // then it clearly means that // number is repeating/ since // we just have to find the // sum of previous two number if (($arr[$i] % 10 == 0) && ($arr[$i+1] % 10 == 1)) break; } echo "Sequence is repeating after", " index ", $i; // This code is contributed by ajit ?> |



