Skip to content

Instantly share code, notes, and snippets.

@ritog
Created April 16, 2021 19:07
Show Gist options
  • Save ritog/0e44d57fdd13197e1dacdc381ef4f2dd to your computer and use it in GitHub Desktop.
Save ritog/0e44d57fdd13197e1dacdc381ef4f2dd to your computer and use it in GitHub Desktop.
Efficient algorithm for 486A of Codeforces
#include <iostream>
using namespace std;
typedef long long int lli;
int main() {
lli n{0};
cin >> n;
if (n == 3) {
cout << -1;
}
else if (n % 2 == 0) {
cout << n / 2;
}
else if (n % 2) {
auto out = (((n / 2) + 1) * (-1));
cout << out;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment