An efficient way to check whether n | A simple Java program to check if n - th Fibonacci number is multiple of 10. ; Returns true if n - th Fibonacci number is multiple of 10. ; main function
class Fibonacci { static int fibonacci ( int n ) { int a = 0 ; int b = 1 ; int c = 0 ; if ( n <= 1 ) return n ; for ( int i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } static boolean isMultipleOf10 ( int n ) { int f = fibonacci ( 30 ) ; return ( f % 10 == 0 ) ; } public static void main ( String [ ] args ) { int n = 30 ; if ( isMultipleOf10 ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }