Hi guys sorry for waiting too long, I just started to working at a startup in Jakarta. So this afternoon, at the office LOL, i just solved one question on codeforce.
It took me several minutes to find the pattern of the question, the pattern are :
1) By using even and odd number :
a) if the number is an even number then we should calculate by using (n/2).
b) then if we found out that the number is an odd one, just calculate it by using ((n+2)+1) *-1
Go and give it a try! the above pattern gave me a solid AC on my second try HAHA*
*beware of the questions that you should use high range variable, I tried using int at first and it gave me an error, then I changed it to long long int so that It can holds the result value.
Ok.. That’s for me now, See you on another post!
#include <iostream>
using namespace std;
int main(void)
{
long long int n;
cin >> n;
long long int res = 0;
if (n == 1){
res = -1;
cout << res << endl;
}else if (n % 2 == 0){
res = (n/2);
cout << res << endl;
}else{
res = ((n/2) + 1) * -1;
cout << res << endl;
}
}
