CUTCAKE - Eat all the brownies !

no tags 

BrownieDude was given the job of cutting cake at a party for serving the guests. But BrownieDude is both lazy and hungry, so he wants to cut the cake into maximum number of pieces with minimum number of cuts and go off to eating brownies. 

The host of the party says that BrownieDude can cut the cake into unequal pieces but cannot cut in more than one plane.(Only vertical cuts are allowed.) Given the number of guests, find the number of cuts sufficient to generate the cake pieces.


First line contains 't', the number of test cases. 't' lines follow. (1 <= t <= 1000)

Each line denotes the number of guests. (1 <= n <= 10^11)


One number denoting the number of cuts.

Note: It is guaranteed that an integer solution will always exist.

Example Input:


Example Output:


Explanation for test cases: If there is only one guest, there is no need to cut the cake. If there are 2 guests, the cake can be cut into 2 pieces in 1 cut.

hide comments
karthik_vg: 2017-07-11 10:43:41

and finally!!!!!!!!........... 100th AC in spoj classic ;)

hunnychauhan: 2017-07-07 09:30:27

pancake cutting problem...
checking for only 1,3,7......

Last edit: 2017-07-13 18:58:17
prasoonbatham: 2016-10-19 17:40:13

Division of a plane by n lines. Simple. :)

blitzzna: 2016-06-25 19:27:36

got it..
test cases can be
2 1
3 2
4 2
5 3
6 3
7 3
8 4
12 5

Last edit: 2016-06-26 18:11:07
akshayvenkat: 2016-06-08 18:33:29

thankyou @harshitdd210

harshitdd120: 2016-03-22 23:57:03

found this link very useful

rishabh_1997: 2016-02-15 21:00:52

my 50th :

Govind Lahoti: 2015-12-14 13:09:16

you can not rearrange the pieces for cutting

Last edit: 2015-12-14 13:09:30
(Tjandra Satria Gunawan)(曾毅昆): 2015-11-26 15:35:49

"Only vertical cuts are allowed" this is misleading statement. got AC after assuming "only straight line cuts are allowed", straight line cut not necessarily vertical, it can be horizontal, diagonal, etc too..

Edit: maybe I don't know what exactly the meaning of the word "vertical" here.. My english is not good.

Last edit: 2015-11-26 15:45:42
Abishek: 2015-09-25 17:26:35

use long long ...long is giving wrong answer .

Added by:Pandian
Time limit:0.390s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)