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 . ; Iterate over 1 to a to find distinct pairs ; For each integer from 1 to a b / n integers exists such that pair / sum is divisible by n ; If ( i % n + b % n ) >= n one more pair is possible ; Return answer ; Driver code
def findCountOfPairs ( a , b , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , a + 1 ) : NEW_LINE INDENT ans += b // n NEW_LINE ans += 1 if ( i % n + b % n ) >= n else 0 NEW_LINE DEDENT return ans NEW_LINE DEDENT a = 5 ; b = 13 ; n = 3 NEW_LINE print ( findCountOfPairs ( a , b , n ) ) NEW_LINE