Divisors and Multiples

Company: Publicis_sapient_22nov

Difficulty: medium

Problem Statement

Divisors and Multiples Problem Description You are given an array arr of n positive integers. For every index i ( 0 <= i < n ), count the number of indices j with j != i such that at least one of the following holds: arr[j] is a divisor of arr[i] , that is arr[i] % arr[j] == 0 arr[j] is a multiple of arr[i] , that is arr[j] % arr[i] == 0 Return the array of these n counts. Note that an index j with arr[j] == arr[i] satisfies both conditions, and must be counted exactly once . Function Description Implement the function getCount : int arr[n] : the array The function returns an integer array of length n , where element i is the count for arr[i] . Input Format For custom testing, standard input contains: Line 1: the integer n Line 2: n integers, the elements of arr Output Format Print the n counts on a single line, separated by single spaces, in the order of the input. Examples Example 1 Input 5 1 3 4 2 6 Output 4 2 2 3 3 Explanation: arr[0] = 1 divides every other element, so all 4