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 ; Test for n = 3 ; Test for n = 4
< ? php function is_prime ( $ num ) { $ count1 = 0 ; for ( $ i = 1 ; $ i * $ i <= ( $ num ) ; $ i ++ ) { if ( ( $ num ) % $ i == 0 ) { if ( $ i * $ i != ( $ num ) ) $ count1 += 2 ; else $ count1 ++ ; } } if ( $ count1 == 2 ) return true ; else return false ; } function is_divisible ( $ n ) { if ( $ n == 1 ) { return " YES " ; } else { if ( is_prime ( $ n + 1 ) ) return " NO " ; else return " YES " ; } } $ n = 3 ; echo is_divisible ( $ n ) . " STRNEWLINE " ; $ n = 4 ; echo is_divisible ( $ n ) . " STRNEWLINE " ; ? >