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.


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.


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



hide comments
kuchnahiaata: 2018-03-28 22:26:16


bayulaxana: 2017-12-30 10:00:10

AC in one Go .. :)
Just find the formula for it...

nihaalbn: 2017-12-09 18:06:33

take care of -1 at the end of input ac in 2nd go ;p

sai__teja_01: 2017-11-29 18:51:20

AC in a go chillar sum da

hitesh87: 2017-10-05 20:18:10

HINTS:google beehive structure

amulyagaur: 2017-07-18 19:07:06

can be done with binary search

ABHISHEK: 2017-05-31 04:27:05

If you are using brute force for the obtained pattern than the time complexity is square root n :)

sagnik_66: 2017-05-20 19:02:34

Googled a picture of a beehive to observe the pattern initially! LOL!
O(1) solution, though!!

looser69: 2017-04-11 19:13:27

simple!! just find the pattern and check for beehive numbers

sushanth_r: 2017-04-01 05:31:36

AC with Brute Force in 0.00 s. Don't try too hard =)

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