# Subarray Sums Divisible by K (Leetcode 974)

Problem Link: <https://leetcode.com/problems/subarray-sums-divisible-by-k/>

```python
class Solution:
    def subarraysDivByK(self, nums: List[int], k: int) -> int:
        
        d={}
        d[0]=1
        s=0
        ans=0
        for i in nums:
            s=s+i
            rem=s%k
            if(rem<0):
                # Make rem positive
                # by adding k
                # Think about it
                rem=rem+k
            if(rem in d):
                ans=ans+d[rem]
                d[rem]+=1
            else:
                d[rem]=1
        
        return ans             
```
