fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ll long long
  5. #define endl "\n"
  6. #define FOR(i, a, b) for (int i = a; i <= b; i++)
  7. #define FORD(i, a, b) for (int i = a; i > b; i--)
  8. #define FORu(i, a, b) for (int i = a; i < b; i++)
  9. #define vii vector <int>
  10. #define pb push_back
  11. #define fi first
  12. #define se second
  13. #define sz(a) (int)a.size()
  14. #define all(x) x.begin(), x.end()
  15. #define filei "BAI3.INP"
  16. #define fileo "BAI3.out"
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  20. if (fopen(filei, "r"))
  21. {
  22. freopen(filei, "r", stdin);
  23. freopen(fileo, "w", stdout);
  24. }
  25. ll a, b, c, m; cin >> a >> b >> c >> m;
  26. vector <int> p = {a, b, c, m}; sort(p.begin(), p.end(), greater <int> ());
  27. if (p[0] == 0) return cout <<(p[1] % m * p[2] % m) % m, 0;
  28. if (p[1] == 0) return cout << 0, 0;
  29. if (p[2] == 0) return cout << (p[0] % m * p[1] % m) % m, 0;
  30.  
  31. if (p[0] > 0)
  32. {
  33. if (p[1] > 0) cout << (p[0] % m * p[1] % m) % m;
  34. else cout <<(p[1] % m * p[2] % m) % m;
  35. }
  36. else
  37. {
  38. cout << (p[0] % m * p[1] % m) % m;
  39. }
  40. }
Success #stdin #stdout 0.01s 5320KB
stdin
2 -3 -2 100
stdout
Standard output is empty