Sort by

recency

|

802 Discussions

|

  • + 0 comments

    this is very dificult if you dont do a little search for the algorithm

  • + 0 comments

    Here is a simple and effective code

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    def nonDivisibleSubset(k, s):
        rem=[0]*k
        for i in range(len(s)):
            rem[s[i]%k]+=1
        count=min(rem[0],1)
        for j in range(1,(k//2)+1):
            if j!=k-j:
                count+=max(rem[j],rem[k-j])
            else:
                count+=min(rem[j],1)
        return count
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        first_multiple_input = input().rstrip().split()
    
        n = int(first_multiple_input[0])
    
        k = int(first_multiple_input[1])
    
        s = list(map(int, input().rstrip().split()))
    
        result = nonDivisibleSubset(k, s)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()
    
  • + 0 comments

    In the comments section was my first solution but the execution time was too long.

    def nonDivisibleSubset(k, s):
        # import itertools
        
        # for r in range(len(s), 0, -1):
        #     for c in itertools.combinations(s, r):
        #         if all(sum(comb) % k != 0 for comb in itertools.combinations(c, 2)):
        #             return len(c)
        # return 0 
        
        from collections import Counter
        
        freq = Counter(num % k for num in s)
    
        count = min(freq.get(0, 0), 1)
    
        for i in range(1, (k // 2) + 1):
            if i == k - i:
                count += 1
            else:
                count += max(freq.get(i, 0), freq.get(k - i, 0))
    
        return count
    
  • + 0 comments

    I admit that it was really difficult to understand the solution to this problem. I had to get help. Or ı am stupid

  • + 0 comments

    I have been having a hard time understanding the answers provided here. Could someone provide a step by step solution for me in pyton.