Pages

Tuesday 24 February 2015

SPOJ PROBLEM 21332. PIGEONHOLE TOWER

Problem Link: http://www.spoj.com/problems/PHT/

SUMMARY:
Pigeon SSNA want to build a tower with some wood walls. Let's describe the tower they want to make:
  1. A Tower can consist of different number of level.
  2. If a tower contain levels then 1st level must contain  holes , 2nd level L-1 , 3rd level L-2 ….. L level contain 1 hole .
  3. Each room contain 3 wood walls.
See the picture below:

                                 3 level                    4level
                                           3 Level Tower                                      4 Level tower

Now pigeon SSNA has n wood walls. What is maximum number of level he can made. 

Logic:
It's a simple mathematics based on n*(n+2) gives you the required solution so we have to find only the value of n.  

To View My Solution:

SPOJ PROBLEM 10575. THE YELLOW BRICKS ROAD

Problem Link: http://www.spoj.com/problems/YELBRICK/

SUMMARY:
Each test case is given using several lines. The first line contains an integer N representing the number of different suppliers of yellow stone (2 ≤ N ≤ 1000). For simplicity, we assume that the engineers will buy exactly one stone from each supplier. Each of the next N lines contains three integers Ai, Bi, Ci (0 < Ai, Bi, Ci ≤ 1000, 1 ≤ i ≤ N) that describe, respectively, the width, height and depth of each stone provided by the i-th supplier. The last test case is followed by a line containing one zero.

For each test case, print one line containing the minimum number of identical cubes that can be cut from the given stones.

Logic
Cubes could be formed when all sides of individual cuboids are divisible by same no. or the volume is perfect cube.

So we have to maximize the volume with minimum number of cubes. So we must divide all sides with a number (a smallest number that divides all the sides).

To View My Solution:

Sunday 15 February 2015

SPOJ PROBLEM 74. DIVISOR SUMMATION

Problem Link: http://www.spoj.com/problems/DIVSUM/

SUMMARY:
Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.
e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.

Logic
The logic for solving this question is that divisors always exist in pairs. So, for a number ‘t’, if ‘i’ is a divisor then ‘t/i’ is also a divisor.
And the smaller number of any divisor pair is always less than or equal to the square root of the number.


To View My Solution:
https://github.com/shivam04/spoj/blob/master/DIVSUM.cpp