Primality test for the sum of digits at odd places of a number | Function that return sum of the digits at odd places ; Function that returns true if the number is prime else false ; Corner cases ; This condition is checked so that we can skip middle five numbers in the below loop ; Driver code ; Get the sum of the digits at odd places
< ? php function sum_odd ( $ n ) { $ sum = 0 ; $ pos = 1 ; while ( $ n ) { if ( $ pos % 2 == 1 ) $ sum += $ n % 10 ; $ n = ( int ) ( $ n / 10 ) ; $ pos ++ ; } return $ sum ; } function check_prime ( $ n ) { if ( $ n <= 1 ) return false ; if ( $ n <= 3 ) return true ; if ( $ n % 2 == 0 $ n % 3 == 0 ) return false ; for ( $ i = 5 ; $ i * $ i <= $ n ; $ i = ( $ i + 6 ) ) if ( $ n % $ i == 0 || $ n % ( $ i + 2 ) == 0 ) return false ; return true ; } $ n = 223 ; $ sum = sum_odd ( $ n ) ; if ( check_prime ( $ sum ) ) echo " YES " ; else echo " NO " ; ? >