Friday, 10 July 2015

AE00

Standard

Rectangles

Link to the question : AE00 

HINT : 

Just a bit of paper work. You can easily get a formula for smaller value of n like 8. But if you go for values n like 10,17 etc. you will notice what exactly needs to be done. If still you dont get how to do it, you can check my source code and see how does it find the answer.

SOURCE CODE :

#include<stdio.h>
#include<math.h>
int main() {
           int n,i,j,k,s=0;
           scanf("%d",&n);
           for(i=1;i<=sqrt(n);i++)
           {
                 k=i*i;
                 if((n/k)>=1)
                  {
                    if(i==1)
                     s = s + n/k;
                     else
                     {
                         for(j=i;j<=n/i;j++)
                         {
                             if(i*j<=n)
                                s=s+1;
                         }
                     }
           }}

           printf("%d",s);
           return 0;
}


0 comments:

Post a Comment