rev='made'/> name='keywords'/> name='author'/> ANURANAN: UVa Solution 11461 : Square Numbers

Welcome Note

Hi,
I'm Anisuzzaman Babla . I am a full stack Android Application Developer. I am working with Android for more than two years. I have completed my graduation from IIT, Jahangirnagar University. I have developed a series of commercially successful apps on Android. Moreover, 10+ of my Apps are live at Google play store. .
Thank You

UVa Solution 11461 : Square Numbers



#include<stdio.h>
#include<math.h>
int main()
{
long int num1,num2,x,sqr,i,j,n1,n2;
while(scanf("%ld%ld",&n1,&n2)==2)
       {
           if(n1==0 &&n2==0)break;
           sqr=0;
           num1=sqrt(n1);
           num2=sqrt(n2);
           for(i=num1;i<=num2;i++)
              {
                     x=pow(i,2);
                     if(x>=n1&&x<=n2) sqr++;
                     if(x>n2)break;
             }
         printf("%ld\n",sqr);
       }
return 0;
  }

3 comments:

  1. i do it as below but i uva judge shows me time limit exit

    #include

    int main()
    {
    int a,b,count,i,j;
    while(scanf("%d%d",&a,&b)==2 && a!=0 && b!=0)
    {
    count=0;
    for(i=a;i<=b;i++)
    {

    for(j=1;j<=(i/2)+1;j++)
    {

    if(i==j*j)
    {
    count++;
    }
    }
    }
    printf("%d\n",count);

    }



    return 0;
    }

    ReplyDelete