Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

ak3899's blog

By ak3899, history, 2 months ago, In English,

what is the intuition behind this question spoj:

i am trying but able to find the correct solution for it please some one help. Btw the question is ::

A knight is located at the (black) origin of an infinite chessboard. Let f(n) define the number of black squares the knight can reach after making exactly n moves. Given n (0 <= n <= 108), output f(n).

 
 
 
 
  • Vote: I like it  
  • -3
  • Vote: I do not like it  

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

int a; cin >> a; cout << ((a&1)^1);

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i did't get it can you elaborate it please.

»
2 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

It is evident that if n is odd then the answer is 0. If n is 0 then the answer is 1. If n > 2 and is even then all reachable black squares form а 'regular' octagon with the side size as (n + 1). You can easily count the number of black squares in it: (2 * n + 1)2 + (2 * n)2 - 4 * (n / 2)2 = 7 * n2 + 4 * n + 1. If n is 2 then not all black squares inside the octagon are rachable for a knight and this equation is not applicable.