Count of pairs from 1 to a and 1 to b whose sum is divisible by N | Function to find the distinct pairs from 1 - a & 1 - b such that their sum is divisible by n . ; if first element is bigger then swap ; count is store the number of pair . ; we use temp for breaking a loop . ; count when a is greater . ; Count when a is smaller but b is greater ; Count when a and b both are smaller ; For storing The pair in count . ; return the number of pairs . ; Driver code
def findCountOfPairs ( a , b , n ) : NEW_LINE INDENT if ( a > b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT temp = 1 NEW_LINE count = 0 NEW_LINE i = n NEW_LINE while ( temp > 0 ) : NEW_LINE INDENT if ( a >= i ) : NEW_LINE INDENT temp = i - 1 NEW_LINE DEDENT elif ( b >= i ) : NEW_LINE INDENT temp = a NEW_LINE DEDENT elif ( i > b ) : NEW_LINE INDENT temp = a - ( i - b ) + 1 NEW_LINE DEDENT if ( temp > 0 ) : NEW_LINE INDENT count += temp NEW_LINE DEDENT i += n NEW_LINE DEDENT return count NEW_LINE DEDENT a = 5 NEW_LINE b = 13 NEW_LINE n = 3 NEW_LINE print ( findCountOfPairs ( a , b , n ) ) NEW_LINE