An efficient way to check whether n-th Fibonacci number is multiple of 10?

Here we will see one efficient way to check whether the nth Fibonacci term is multiple of 10 or not. Suppose the Fibonacci terms are {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987}. So here 15th (counting from 0) Fibonacci term is divisible by 10.

One easiest method is generating Fibonacci numbers up to given term, and check whether it is divisible by 10 or not. But this solution is not good, because it will not work for larger terms due to overflow and time complexity issues.

Approach

The key insight is based on the divisibility pattern of Fibonacci numbers −

  • Every 3rd Fibonacci number is divisible by 2: F(3), F(6), F(9), F(12), F(15)...
  • Every 5th Fibonacci number is divisible by 5: F(5), F(10), F(15), F(20)...

For a Fibonacci number to be divisible by 10, it must be divisible by both 2 and 5. Since LCM(3, 5) = 15, every 15th Fibonacci number is divisible by 10.

Fibonacci Divisibility Pattern F(0)=0 ÷10 ? F(15)=610 ÷10 ? F(30) ÷10 ? F(45) ÷10 ? F(60) ÷10 ? 15 positions 15 positions Every 15th Fibonacci number is divisible by 10

Algorithm

fiboDivTen(term)
Begin
   if term is divisible by 15, then
      return true
   end if
   return false
End

Example

Here's the C implementation to check if nth Fibonacci number is divisible by 10 −

#include <stdio.h>
#include <stdbool.h>

bool fiboDivTen(int term) {
    if(term % 15 == 0) {
        return true;
    }
    return false;
}

int main() {
    int term = 45;
    printf("Checking if F(%d) is divisible by 10: ", term);
    
    if (fiboDivTen(term)) {
        printf("Yes, F(%d) is divisible by 10<br>", term);
    } else {
        printf("No, F(%d) is not divisible by 10<br>", term);
    }
    
    /* Test with multiple values */
    int test_values[] = {0, 15, 30, 45, 60, 13, 17, 22};
    int n = sizeof(test_values) / sizeof(test_values[0]);
    
    printf("\nTest Results:<br>");
    for(int i = 0; i < n; i++) {
        printf("F(%d): %s<br>", test_values[i], 
               fiboDivTen(test_values[i]) ? "Divisible by 10" : "Not divisible by 10");
    }
    
    return 0;
}
Checking if F(45) is divisible by 10: Yes, F(45) is divisible by 10

Test Results:
F(0): Divisible by 10
F(15): Divisible by 10
F(30): Divisible by 10
F(45): Divisible by 10
F(60): Divisible by 10
F(13): Not divisible by 10
F(17): Not divisible by 10
F(22): Not divisible by 10

Time and Space Complexity

  • Time Complexity: O(1) − constant time operation
  • Space Complexity: O(1) − no extra space required

Key Points

  • This method works for extremely large values of n without overflow issues
  • Based on the mathematical property that every 15th Fibonacci number is divisible by 10
  • Much more efficient than generating actual Fibonacci numbers

Conclusion

The efficient approach to check if the nth Fibonacci number is divisible by 10 is simply checking if n is divisible by 15. This method has O(1) complexity and avoids the computational overhead of generating large Fibonacci numbers.

Updated on: 2026-03-15T11:13:10+05:30

342 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements