Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, m, wynik=1, zm;
  4. int prefix[1000004], zlicz[1000004];
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. prefix[0]=0;
  9. cin>>n>>m;
  10. for (int i=1; i<=n; i++)
  11. {
  12. cin>>zm;
  13. prefix[i]=prefix[i-1]+zm;
  14. prefix[i]=prefix[i]%m;
  15. }
  16. for (int i=1; i<=n; i++)
  17. zlicz[prefix[i]]++;
  18.  
  19. for (int i=1; i<=n; i++)
  20. {
  21. if (prefix[i]==0){wynik+=zlicz[0]; continue;}
  22. zlicz[prefix[i]]--;
  23. wynik+=zlicz[prefix[i]];
  24. }
  25. cout<<wynik;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement