Primality test for the sum of digits at odd places of a number | Function that return sum of the digits at odd places ; Function to check if a number is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; driver code ; Get the sum of the digits at odd places
def sum_odd ( n ) : NEW_LINE INDENT sums = 0 NEW_LINE pos = 1 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT if ( pos % 2 == 1 ) : NEW_LINE INDENT sums += n % 10 NEW_LINE DEDENT n = n // 10 NEW_LINE pos += 1 NEW_LINE DEDENT return sums NEW_LINE DEDENT def check_prime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 5 , n , 6 ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT n = 223 NEW_LINE sums = sum_odd ( n ) NEW_LINE if ( check_prime ( sums ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT