BEENUMS - Beehive Numbers

no tags 

A beehive is an enclosed structure in which some honey bee species live and raise their young. In this problem we consider a two-dimensional sketch of the beehives. Each beehive is composed of a certain number of cells, where each cell is a regular hexagon. Each cell may have some neighbors, which are other cells that share a side with that cell. A cell with exactly 6 neighbors is an internal cell, while a cell with fewer neighbors is an external one. Notice that an external cell can always be changed to internal by adding some neighbor cells.

We are interested in a particular class of beehives. This class of valid beehives is defined recursively as follows: a) a single cell is a valid beehive; and b) given a valid beehive B, if we add the minimum number of cells such that each external cell of B becomes an internal cell, the result is a valid beehive.

The number of cells in a valid beehive is called a beehive number. Given an integer N, you must decide whether it is a beehive number.

Input

Each test case is described using a single line. The line contains an integer N (1 ≤ N ≤ 109). The end of input is indicated with a line containing a single −1.

Output

For each test case, output a single line containing an uppercase “Y” if N is a beehive number, or an uppercase “N” otherwise.

Example

Input:
43
1
7
19
15
-1

Output:
N
Y
Y
Y
N

hide comments
lalit_nit: 2016-02-09 04:51:17

Just by Given TestCases and Brute Force => :)

Last edit: 2016-02-09 04:51:57
akshayvenkat: 2016-01-12 09:25:57

pretty simple logic. (4*n-1)/3 is perfect square , its a beehive number. thank you @ashish

Last edit: 2016-03-09 16:36:53
ABHISHEK RAJPUT: 2015-12-17 20:49:17

construct beehive structure by yourself first...see series,make formula and
apply brute force, it will do it. happy coding :)

rajesh1995: 2015-11-25 04:38:52

easy...at every level 6*(n-1) added to next level....brute approach....acptd

sumit suthar: 2015-11-14 06:35:47

Take it eazy... :)

alexbandeira: 2015-09-22 21:01:28

one line: return rec(n,s+=(*****),i+1); (=

Last edit: 2015-09-22 21:02:04
Abishek: 2015-09-12 16:05:55

don't think hard ! brute force got accepted !

Shivam Singh: 2015-08-24 11:03:30

Level 1 - 1
Level 2 - 7
Level 3 - 19
Level 4 - 37
Level 5 - 61 and so on...
seems quadratic a*(h^2)+b*h+c=n ;)

Ashish: 2015-08-19 15:49:09

N is beehive iff (4N-1)/3 is a perfect square. This problem is pretty shitty.

Last edit: 2015-08-19 17:14:05
r0bo_dart: 2015-07-21 18:58:27

this might look awkward, but i used an actual beehive for reference :P


Added by:Pablo Ariel Heiber
Date:2010-09-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:FCEyN UBA ICPC Selection 2010