Check if factorial of N is divisible by the sum of squares of first N natural numbers | Function to count number of times prime P divide factorial N ; Lengendre Formula ; Function to find count number of times all prime P divide summation ; Formula for summation of square after removing n and constant 6 ; Loop to traverse over all prime P which divide summation ; If Number itself is a Prime Number ; Driver Code
< ? php function checkfact ( $ N , $ countprime , $ prime ) { $ countfact = 0 ; if ( $ prime == 2 $ prime == 3 ) $ countfact ++ ; $ divide = $ prime ; while ( ( int ) ( $ N / $ divide ) != 0 ) { $ countfact += ( int ) ( $ N / $ divide ) ; $ divide = $ divide * $ divide ; } if ( $ countfact >= $ countprime ) return true ; else return false ; } function check ( $ N ) { $ sumsquares = ( $ N + 1 ) * ( 2 * $ N + 1 ) ; $ countprime = 0 ; for ( $ i = 2 ; $ i <= sqrt ( $ sumsquares ) ; $ i ++ ) { $ flag = 0 ; while ( $ sumsquares % $ i == 0 ) { $ flag = 1 ; $ countprime ++ ; $ sumsquares = ( int ) ( $ sumsquares / $ i ) ; } if ( $ flag == 1 ) { if ( checkfact ( $ N - 1 , $ countprime , $ i ) ) return false ; $ countprime = 0 ; } } if ( $ sumsquares != 1 ) if ( checkfact ( $ N - 1 , 1 , $ sumsquares ) ) return false ; return true ; } $ N = 5 ; if ( check ( $ N ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >