Demo entry 3548858

cpp

   

Submitted by anonymous on Jan 19, 2016 at 14:27
Language: C++. Code size: 425 Bytes.

#include <iostream>
using namespace std;
typedef unsigned long long ull;
typedef long long sll;
int main(void)  {
	sll in;
	cin >> in;

	if (in == 0) {
		cout << 1 << endl;
		return 0;
	}
	bool negative = (in < 0);

	ull n = abs(in);

	ull s;
	if (n&1ULL) {
		s = (n + 1ULL) / 2ULL;
		s *= n;
	} else {
		s = n / 2ULL;
		s *= n + 1ULL;
	}

	if (negative)
		s--;

	if (negative && s)
		cout << "-";

	cout << s;

	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).