Count of coprimes in two array

There are two arrays A and B both of size of N and we need to return the count of pairs (i ,j) where gcd(A[i],B[j])==1.



Input Format:

    First argument of input contains an integer array A
    Second argument of input contains an integer array B

Output Format:

    return an integer denoting count of pairs.

Constraints:

    1 <= N <= 46000
    2 <= A[i],B[i] <= 1e9

For Example:

Example Input 1:
    A = [6, 2, 3], B = [4, 5, 6]
Example Output 1:
    4
Explanation 1:
    Four pairs are (1, 2), (2, 2), (3, 1), (3, 2)
Example Input 2:
    A = [2, 3, 4, 5], B = [6, 7, 8, 9]
Example Output 2:
    10
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Count of coprimes in two array on Interview Code Editor
Sign Up
to access hints and editorial solutions for Count of coprimes in two array

Discussion


Loading...
Click here to start solving coding interview questions