Check whether factorial of N is divisible by sum of first N natural numbers | Function to check whether a number is prime or not . ; Count variable to store the number of factors of ' num ' ; Counting the number of factors ; If number is prime return true ; Function to check for divisibility ; if ' n ' equals 1 then divisibility is possible ; Else check whether ' n + 1' is prime or not ; If ' n + 1' is prime then ' n ! ' is not divisible by ' n * ( n + 1 ) / 2' ; else divisibility occurs ; Driver Code ; Test for n = 3 ; Test for n = 4
function is_prime ( num ) { var count = 0 ; for ( i = 1 ; i * i <= ( num ) ; i ++ ) { if ( ( num ) % i == 0 ) { if ( i * i != ( num ) ) count += 2 ; else count ++ ; } } if ( count == 2 ) return true ; else return false ; } function is_divisible ( n ) { if ( n == 1 ) { return " " ; } else { if ( is_prime ( n + 1 ) ) return " " ; else return " " ; } } var n ; n = 3 ; document . write ( is_divisible ( n ) + " " ) ; n = 4 ; document . write ( is_divisible ( n ) ) ;