hot3eed's blog

By hot3eed, history, 3 years ago, In English,

The formula I'm asking about in problem 486A is the one in most C++ answers which is: n/2-n*(n%2), now where does this formula come from? Also, I found this solution in which the author says that he looked for a pattern (tldr; if the number is even then n/2 or else if it's odd then -1 * ((n+1)/2)) until he found one which actually works, is there any explanation for this pattern? Also, is this kind of patterns a matter of trial and error or is there a way to identify them?

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it