Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

1167. Move To Invert

Problem code: MINCOUNT

A triangle made of coins of height h is as follows
It has h coins at the base and h-1 coins one level above base and so on.(Coins are placed as shown in the figure below)
And at the top most level there will be only one coin
Now given h the task is to invert this triangle by moving minimum number of coins. For example when h=4 triangle is
Invert
For h=4 at least 3 coins must be moved to invert it.

Input

In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case.00≤h<1010;

Output

For each test case output in a seperate line the minimum number of moves required to invert the triangle. Output fits in long long data type

Example

Inputt:
1
3

Output:
2

Added by:Abhilash I
Date:2006-12-16
Time limit:1s
Source limit:50000B
Languages:All except: ERL JS
Resource:IIIT Hyderabad Local Programming Contest

hide comments
2012-03-23 13:51:04 vD


Last edit: 2012-03-23 13:52:51
2012-02-06 15:30:14 dutte
uses simple mathematics
but remember to use printf, scanf("%lli").....
and submit with c compiler
2012-02-06 15:29:46 codecracker
it uses very simple mathematics...........
2012-01-09 00:36:57 Albert Chen
Yes... h can be 0.
2011-12-12 15:31:56 MR. BEAN
answer for 100 is 1683 and for 10^10 is 7443294631478557525 !!!
2011-10-05 23:55:49 sri
is the solution for 100 is 1875???
i am not getting 1683.
help me out.
2011-07-22 10:46:37 Pavel Simo
weak test cases accepted with long long...
2011-07-21 23:15:41 Vinay Chaudhary
WTH its not that complicated....analyse the output till 10 you will figure it out..:)..use scanf and printf instead of cin and cout
2011-07-16 12:16:12 The Champ
why ERL is not allowed?
2011-05-21 17:59:03 Ɲagesh
nice problem...:D
Just simple mathematics!!!
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.