You are viewing a single comment's thread. Return to all comments →
i didnt understand your code. but here is another algorithm works with O(n)
def search(numbers,k): numberofways=int() for i in range(len(numbers)-1): for j in range(i+1,len(numbers)): if (numbers[i]+numbers[j])%k==0: numberofways+=1 return numberofways number=list() n=int(input()) k=int(input()) for i in range(n): number.append(int(input())) print(search(number,k))
Seems like cookies are disabled on this browser, please enable them to open this website
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →
i didnt understand your code. but here is another algorithm works with O(n)