You are given an integer N. For each integer i from 2 to N, assign a positive integer Ali] such that the following conditions hold:
• For any pair of integers (i, j), if i and j are co-prime, then A[i]! = A[j].
• The maximum value among all A[i] is the minimum possible.
Please view the full question image from the below link :
https://drive.google.com/file/d/1_XuTnf6ymzvsP7-z0zA5DJnQdchyHTQs/view?usp=sharing
# Python3 implementation of the approach
# Function to return the count
# of unique pairs in the array
def getPairs(arr, n) :
# Set to store unique pairs
h = set()
for i in range(n - 1) :
for j in range(i + 1, n) :
# Create pair of (a[i], a[j])
# and add it to the hashset
h.add((arr[i], arr[j]));
# Return the size of the HashSet
return len(h);
# Driver code
if __name__ == "__main__" :
arr = [ 1, 2, 2, 4, 2, 5, 3, 5 ]
n = len(arr)
print(getPairs(arr, n))
Comments
Leave a comment