Answer to Question #280546 in Python for Rahul Sigh

Question #280546

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
1
Expert's answer
2021-12-20T10:03:54-0500
# 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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS