简体   繁体   中英

Find the sum of count of the numbers in which array elements are divided

Given an array of N positive integers and a number K where K is used as a threshold value to divide each element of the array into sum of different numbers. Find the sum of count of the numbers in which array elements are divided.

Input: N = 4, K = 3 Arr[] = {5, 8, 10, 13} Expected Output: 14

def totalCount(self, arr, n, k):  

for i in range(0, n):
    if (arr[i]%k==0) and (count = arr[i]/k):
      return 1
count1 = arr[i]/k+1

sum = count + count1
return sum

I too don't know the answer and as I am searing for it I encounter this and the explanation for the above is

N = 4, K = 3
a[] = {5, 8, 10, 13}
Output: 14

Explanation: Each number can be expressed as sum of different numbers less than or equal to K as 5 (3 + 2), 8 (3 + 3 + 2), 10 (3 + 3 + 3 + 1), 13 (3 + 3 + 3 + 3 + 1). So, the sum of count of each element is (2+3+4+5)=14.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM