Check if the door is open or closed | Function to check whether ' n ' has even number of factors or not ; if ' n ' is a perfect square it has odd number of factors ; else ' n ' has even number of factors ; Function to find and print status of each door ; If even number of factors final status is closed ; else odd number of factors final status is open ; Driver Code
< ? php function hasEvenNumberOfFactors ( $ n ) { $ root_n = sqrt ( $ n ) ; if ( ( $ root_n * $ root_n ) == $ n ) return false ; return true ; } function printStatusOfDoors ( $ n ) { for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { if ( hasEvenNumberOfFactors ( $ i ) ) echo " closed " , " ▁ " ; else echo " open " , " ▁ " ; } } $ n = 5 ; printStatusOfDoors ( $ n ) ; ? >