Check if a large number is divisible by 13 or not | Returns true if number is divisible by 13 else returns false ; Append required 0 s at the beginning . ; Same as strcat ( num , "00" ) ; in c . ; Same as strcat ( num , "0" ) ; in c . ; Alternatively add / subtract digits in group of three to result . ; Store group of three numbers in group variable . ; Generate alternate series of plus and minus ; Driver code
def checkDivisibility ( num ) : NEW_LINE INDENT length = len ( num ) NEW_LINE if ( length == 1 and num [ 0 ] == '0' ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( length % 3 == 1 ) : NEW_LINE INDENT num = str ( num ) + "00" NEW_LINE length += 2 NEW_LINE DEDENT elif ( length % 3 == 2 ) : NEW_LINE INDENT num = str ( num ) + "0" NEW_LINE length += 1 NEW_LINE DEDENT sum = 0 NEW_LINE p = 1 NEW_LINE for i in range ( length - 1 , - 1 , - 1 ) : NEW_LINE INDENT group = 0 NEW_LINE group += ord ( num [ i ] ) - ord ( '0' ) NEW_LINE i -= 1 NEW_LINE group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10 NEW_LINE i -= 1 NEW_LINE group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100 NEW_LINE sum = sum + group * p NEW_LINE p *= ( - 1 ) NEW_LINE DEDENT sum = abs ( sum ) NEW_LINE return ( sum % 13 == 0 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT number = "83959092724" NEW_LINE if ( checkDivisibility ( number ) ) : NEW_LINE INDENT print ( number , " is ▁ divisible ▁ by ▁ 13 . " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( number , " is ▁ not ▁ divisible ▁ by ▁ 13 . " ) NEW_LINE DEDENT DEDENT