Advertisement
cyter

mod_sum

Sep 11th, 2018
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. /**
  7. The program:
  8. You must find the sum of the mods of a list of numbers.
  9. Modular arithmetic refers to the remainder of the divide function. A mod B = the remainder of A/B.
  10.  
  11. For example:
  12. 5 mod 2 = 1
  13. 15 mod 6 = 3
  14.  **/
  15.  
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20.     int M, s;
  21.     cin >> M; cin.ignore();
  22.     int N;
  23.     cin >> N; cin.ignore();
  24.     for (int i = 0; i < N; i++) {
  25.         int E;
  26.         cin >> E; cin.ignore();
  27.         s += E % M;
  28.     } cout<< s;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement