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
def is_prime ( num ) : NEW_LINE ' NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , num + 1 ) : NEW_LINE INDENT if i * i > num : NEW_LINE INDENT break NEW_LINE DEDENT if ( ( num ) % i == 0 ) : NEW_LINE INDENT if ( i * i != ( num ) ) : NEW_LINE INDENT count += 2 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT if ( count == 2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def is_divisible ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return " YES " NEW_LINE DEDENT else : NEW_LINE DEDENT ' NEW_LINE INDENT if ( is_prime ( n + 1 ) ) : NEW_LINE INDENT return " NO " NEW_LINE DEDENT else : NEW_LINE INDENT return " YES " NEW_LINE DEDENT DEDENT n = 3 NEW_LINE print ( is_divisible ( n ) ) NEW_LINE n = 4 NEW_LINE print ( is_divisible ( n ) ) NEW_LINE