Maximum subset which has no sum of two divisible by K

后端 未结 5 861
栀梦
栀梦 2021-02-14 16:49

I am given the set {1, 2, 3, ... ,N}. I have to find the maximum size of a subset of the given set so that the sum of any 2 numbers from the subset is not divisible by a given n

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 17:14

    n,k=(raw_input().split(' '))
    n=int(n)
    k=int(k)
    l=[0 for x in range(k)]
    d=[int(x) for x in raw_input().split(' ')]
    flag=0
    for x in d:
       l[x%k]=l[x%k]+1
    
    sum=0
    
    if l[0]!=0:
        sum+=1 
    if (k%2==0):
        sum+=1
    
    
    if k==1:
        print 1
    elif k==2:
        print 2 
    else:       
        i=1
        j=k-1
        while i=l[j] else l[j])
            i=i+1
            j=j-1
         print sum
    

提交回复
热议问题