Page 1 of 2
11461 - Square Numbers
Posted: Sat Aug 09, 2008 7:14 am
by sirius
It's been 2 weeks since the first time i tried to solve this problem,
but i keep getting WA...
Code: Select all
#include <stdio.h>
main() {
long a,b,i,j;int k,n;
scanf("%ld %ld",&a,&b);k = 0;
while (a!=0 || b!=0){
n = 0;k++;if(k!=1)printf("\n");
for(i=1;i*i<a;i++);
for(j=i;j*j<=b;j++)n++;
printf("%d",n);
scanf("%ld %ld",&a,&b);
}
return 0;
}
I joined the online judge competition since July 26th 2008,
and even after send submission 55 times,i can't solve anything...
I would really appreciate it,if someone could help me and tell me what's wrong...THANK YOU!!
Re: 11461 - Square Number
Posted: Sat Aug 09, 2008 8:01 am
by Bluefin
Hey, sirius
I solved this problem minutes ago.
my algorithm is
1. calculate from 1 to b how many numbers are square numbers.
2. calculate from 1 to a - 1 how my numbers are square numbers. (If a = 1, the obvious answer is 0)
3. step 1 - step 2 , and print the answer
to calculate the square numbers, you can use functions like sqrt or floor.
Hope this will help you
![:D](./images/smilies/icon_biggrin.gif)
Re: 11461 - Square Number
Posted: Sat Aug 09, 2008 10:09 am
by sohel
@sirius: There is a new line after every case. So, remove this part "if(k!=1)printf("\n");" and add a newline after printing the output. That is, printf("%ld\n", n);
@Bluefin: sqrt & floor aren't STL functions.
Re: 11461 - Square Number
Posted: Mon Aug 25, 2008 11:08 pm
by chinmoy kanti dhar
why compiler error?????
Code: Select all
#include <stdio.h>
#include<math.h>
void main()
{
long m,n,a,b;
while(scanf("%ld %ld",&a,&b))
{
if(a==0&&b==0)break;
m=sqrt(a);
if(m*m==a)m--;
n=sqrt(b);
m=n-m;
printf("%ld\n",m);
}
}
Re: 11461 - Square Number
Posted: Tue Aug 26, 2008 11:41 am
by RC's
change your void main() into int main()
Re: 11461 - Square Number
Posted: Sat Aug 14, 2010 11:47 am
by noor_aub
Why I am getting W/A
My Code is :
Code: Select all
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long a,b;
while(1)
{
cin>>a>>b;
if(b==0&&a==0)
break;
cout<<long(sqrt(b)-(sqrt(a-1)))<<endl;
}
return 0;
}
Re: 11461 - Square Number
Posted: Sat Aug 14, 2010 3:27 pm
by helloneo
Re: 11461 - Square Number Why WA ????
Posted: Fri Nov 12, 2010 9:32 pm
by ruhul_sust
// please find the Error !!!!!!!!!!
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
long long int a, b, temp;
long long int i, m=0;
while(scanf("%lld%lld", &a, &b)==2)
{
if(a==0 && b==0)
break;
if(a>b)
{
temp = a;
a = b;
b = temp;
}
for(i=a; i<=b; i++)
{
if(sqrt(i) == i/sqrt(i))
{
// printf("%d ", i);
m++;
}
}
printf("%lld\n", m);
m=0;
}
return 0;
}
Re: 11461 - Square Number
Posted: Fri Jan 03, 2014 1:42 pm
by uDebug
Here's some input / output that I found useful during testing / debugging.
Input:
Code: Select all
1 4
1 10
4 9
4 49
3 50
9 50
9 48
8 49
10 49
49 49
1 100000
254 34832
0 0
AC Output:
Re: 11461 - Square Number Why WA ????
Posted: Fri Jan 03, 2014 1:50 pm
by uDebug
ruhul_sust wrote:// please find the Error !!!!!!!!!!
Try the test cases I posted. Your code doesn't handle the last two inputs correctly.
11461 - Square Numbers
Posted: Fri Mar 28, 2014 12:22 pm
by MikhailVladelin
why i'm getting wrong answer ? :/
here's my code
http://paste.ubuntu.com/7167528/
Re: 11461 - Square Numbers
Posted: Fri Mar 28, 2014 10:33 pm
by brianfry713
That is AC code.
Re: 11461 - Square Numbers
Posted: Fri Mar 28, 2014 10:35 pm
by MikhailVladelin
brianfry713 wrote:That is AC code.
AC means accepted ? i'm getting wrong answer all the time
![:(](./images/smilies/icon_frown.gif)
Re: 11461 - Square Numbers
Posted: Mon Mar 31, 2014 11:14 pm
by brianfry713
I just submitted that code you posted and got AC.
11461 - Square Numbers
Posted: Tue Jul 15, 2014 9:54 pm
by Shahidul.CSE
I had tried with 3 ways, but evertimes I have got WA.
Whats going wrong with my codes?
way-1:
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long long int a , b,coun;
while(scanf("%lld %lld",&a,&b) && (a!=0 || b!=0))
{
coun=sqrt(b)+1-sqrt(a);
printf("%lld\n",coun);
}
return 0;
}
way-2:
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long long int a , b,coun;
while(scanf("%lld %lld",&a,&b) && (a!=0 || b!=0))
{
coun=sqrt(b)-sqrt(a-1);
printf("%lld\n",coun);
}
return 0;
}
way-3:
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long long int a , b,i,coun;
while(scanf("%lld %lld",&a,&b) && (a!=0 || b!=0))
{
coun=0;
for(i=a;i<=b;i++)
{
if(i==sqrt(i)*sqrt(i))
coun++;
}
printf("%lld\n",coun);
}
return 0;
}