Skip to main content

SPOJ 4300 - Rectangles

Problem Statement

Hint: If the input is 15 squares
rectangles are-
                1x1 1x2 1x3 ...................................1x15
                       2x2 2x3 ............................2x7    
                              3x3   ....................3x5
                        
  • can't make 3x2 cause 3x2 and 2x3 are same.
  • can't make 2x8 cause that requires 16 squares.
  • can't make 4x4 cause that also requires 16 square. 
Solution:

#include<stdio.h>
int main()
{
    int n,c=0,i,j;
    scanf("%d",&n);
    for(i=1;i*i<= n;i++)
    {
        c+= (n/i)-i+1;
    }
    printf("%d\n",c);
}


* If there's any query or mistake, let me know.

Comments

Popular posts from this blog

SPOJ - GSS1

Considering input series: { 4 , -10 , 3 , 100 , -20 , 1 } Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y } A node contains-  [ START & END is a node's segment limit ] Prefix is the maximum sum starting at START, end can be anywhere. There are two possibilities of the maximum. One, node's leftChild's prefix or two, adding leftChild's sum + rightChild's prefix. (which will make the prefix contiguous) Suffix is the maximum sum ending at END, start can be anywhere. There's two possibility of the maximum. One, node's rightChild's already calculated suffix or two, add rightChild's sum + leftChild's suffix   (which will make the suffix contiguous). Sum : leftChild's sum + rightChild's sum. MAX Maximum of  -  prefix (result is in the node, starts from START but doesn't end in END ) suffix  (result is in the node, doesn't start from START but surely ends in END ) leftChild's max ( result is in left ...

Bitwise Sieve w/ code sample

Sieve of Eratosthenes is explained HERE Bitwise sieve is an optimized implementation of  Sieve of Eratosthenes. It does the same thing but more memory efficient because it uses logic operations( &,|,>>,<< ) on binary numbers. In normal implementation, we use an array as flag to check if a number is prime or not.we know index of an array ( i.e  myarray[n]  ) is 32 bit long. If an array is 10 index long, that it has 32x10(=320) bits.  We use bits of that array as flag. that way we can flag numbers upto 320 as prime or not prime. i.e, how to check the flag status of 51 in myarray[ n ] ? We'll divide 5 by 32, that will give us the index number of the certain bit, then we'll mod 5 by 32, that will give us the certain bit position to check for 0 or 1. Remember bit positions are defined from right to left, starting from 0. Meaning LST = 0 and MST = 31. So we need to define two functions, one to set that certain bit as 0 or 1, another to check if...

SPOJ - ENIGMATH solution C++

Problem Statement: ENIGMATH - PLAY WITH MATH Heuristic: Ax - By = 0   has two possible cases:   a can divide b or if b can divide a  and you can figure out the rest.  a or b cannot divide the other so it will be A B - B A = 0, but we still have to find the minimum x & y.