Derga

Untitled

Jun 13th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdint>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int64_t S1(int64_t n) {
  8. if (n > 0) return (1 + n) / 2 * n;
  9. else return (1 + n) / 2 * (2 - n);
  10. }
  11.  
  12. int64_t S2(int n) {
  13. int64_t sum = 0;
  14. for (int i = min(1, n); i <= max(1, n); ++i) {
  15. sum += i;
  16. }
  17. return sum;
  18. }
  19.  
  20. int main() {
  21. cout << S1(-5) << ' ' << S2(-5) << ' ' << -5 << '\n';
  22.  
  23. for (int i = 0; i <= 10'000; --i) {
  24. if (S1(i) != S2(i)) {
  25. cout << S1(i) << ' ' << S2(i) << ' ' << i << '\n';
  26. }
  27. }
  28.  
  29. /*
  30. int64_t n;
  31. cin >> n;
  32. cout << S2(n);
  33. return 0;
  34. */
  35. }
Advertisement
Add Comment
Please, Sign In to add comment