fork download
  1. int sub_div(vector<int>& arr, int k)
  2. {
  3. map<int, int> mp;
  4. mp[0]++;
  5.  
  6. int ans = 0, sum = 0;
  7. for(int i=0; i < arr.size(); i++)
  8. {
  9. sum += arr[i];
  10. int tmp = ((sum % k) + k) % k; // NOTE - prefix sum can be -ve --> add k
  11.  
  12. ans += mp[tmp];
  13. mp[tmp]++;
  14. }
  15. return ans;
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:13: error: ‘vector’ was not declared in this scope
 int sub_div(vector<int>& arr, int k)
             ^~~~~~
prog.cpp:1:20: error: expected primary-expression before ‘int’
 int sub_div(vector<int>& arr, int k)
                    ^~~
prog.cpp:1:31: error: expected primary-expression before ‘int’
 int sub_div(vector<int>& arr, int k)
                               ^~~
prog.cpp:1:36: error: expression list treated as compound expression in initializer [-fpermissive]
 int sub_div(vector<int>& arr, int k)
                                    ^
stdout
Standard output is empty