Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cstdint>
- #include <iostream>
- using namespace std;
- int64_t S1(int64_t n) {
- if (n > 0) return (1 + n) / 2 * n;
- else return (1 + n) / 2 * (2 - n);
- }
- int64_t S2(int n) {
- int64_t sum = 0;
- for (int i = min(1, n); i <= max(1, n); ++i) {
- sum += i;
- }
- return sum;
- }
- int main() {
- cout << S1(-5) << ' ' << S2(-5) << ' ' << -5 << '\n';
- for (int i = 0; i <= 10'000; --i) {
- if (S1(i) != S2(i)) {
- cout << S1(i) << ' ' << S2(i) << ' ' << i << '\n';
- }
- }
- /*
- int64_t n;
- cin >> n;
- cout << S2(n);
- return 0;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment