NFURY - Training Land of Fury

S.H.I.E.L.D. is recruiting soldiers for the battle with Loki's army. Nick Fury has come to Manhattan to find a large area of land to be used for training purposes. He meets a popular landlord there who is a little foolish by nature.
He gives square pieces of land with integral sides and charges on the basis of number of pieces of land bought irrespective of how large a piece of land is. Fury has to buy exactly A square units of land. Help Fury by determining the minimum number of pieces that should be bought in order to minimize the expenditure.


The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains a single integer A denoting the area that nick fury want to buy.

  • 10T100000
  • 1A1000


For each test case print the minimum number of pieces that should be bought.





For the last test case 10 the answer will be 2. 10 can be expressed as sum of minimum two squares that is 10 = 32+12.

hide comments
pranjal_rai: 2017-10-19 14:38:08

Can their be multiple square piece of same size?

sagar_zhcet: 2017-06-27 14:58:22

nice problem for the learner of dp like me
enjoyed solving it :)

anurag44: 2017-06-16 17:10:53

nyc prblm..

akshayvenkat: 2016-07-07 07:21:32

AC in one go :D

singh1495: 2016-06-14 17:49:27

easy dp just apply precomputation.............. love u dp.......

KD : 2016-05-28 10:02:20

1st dp -->AC in go :P

nihil_5596: 2016-01-13 20:39:14

1st time AC in 1 go! :)

mr_lazy: 2015-08-08 22:26:44

Cake walk question :P

Scape: 2015-07-25 17:36:05

What is the purpose of setting T <= 10^5 when A <= 10^3? Why not make the other way around?

[Mayank Pratap]: 2015-06-12 18:17:51

Going to be recruited in shield :) :)

Added by:BLANKRK
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Code Weavers 2013