11461 - Square Numbers

All about problems in Volume 114. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sirius
New poster
Posts: 4
Joined: Sat Aug 09, 2008 6:51 am

11461 - Square Numbers

Post by sirius » Sat Aug 09, 2008 7:14 am

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!!

Bluefin
New poster
Posts: 20
Joined: Sat Jul 08, 2006 3:39 pm
Contact:

Re: 11461 - Square Number

Post by Bluefin » Sat Aug 09, 2008 8:01 am

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
Last edited by Bluefin on Sat Aug 09, 2008 2:28 pm, edited 1 time in total.
"It's nice to be important, but it's more important to be nice"

http://bluefintuna.wordpress.com/

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11461 - Square Number

Post by sohel » Sat Aug 09, 2008 10:09 am

@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.

chinmoy kanti dhar
New poster
Posts: 19
Joined: Fri Jun 22, 2007 6:17 pm
Location: bangladesh

Re: 11461 - Square Number

Post by chinmoy kanti dhar » Mon Aug 25, 2008 11:08 pm

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);
}

}


RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm

Re: 11461 - Square Number

Post by RC's » Tue Aug 26, 2008 11:41 am

change your void main() into int main()

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

Re: 11461 - Square Number

Post by noor_aub » Sat Aug 14, 2010 11:47 am

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;
}


helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11461 - Square Number

Post by helloneo » Sat Aug 14, 2010 3:27 pm

Try this

Code: Select all

4 9
0 0
My output is..

Code: Select all

2

ruhul_sust
New poster
Posts: 5
Joined: Tue Jul 27, 2010 8:01 pm

Re: 11461 - Square Number Why WA ????

Post by ruhul_sust » Fri Nov 12, 2010 9:32 pm

// 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;
}

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11461 - Square Number

Post by uDebug » Fri Jan 03, 2014 1:42 pm

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:

Code: Select all

2
3
2
6
6
5
4
5
4
1
318
171
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11461 - Square Number Why WA ????

Post by uDebug » Fri Jan 03, 2014 1:50 pm

ruhul_sust wrote:// please find the Error !!!!!!!!!!
Try the test cases I posted. Your code doesn't handle the last two inputs correctly.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

MikhailVladelin
New poster
Posts: 2
Joined: Fri Mar 28, 2014 12:12 pm

11461 - Square Numbers

Post by MikhailVladelin » Fri Mar 28, 2014 12:22 pm

why i'm getting wrong answer ? :/
here's my code

http://paste.ubuntu.com/7167528/

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11461 - Square Numbers

Post by brianfry713 » Fri Mar 28, 2014 10:33 pm

That is AC code.
Check input and AC output for thousands of problems on uDebug!

MikhailVladelin
New poster
Posts: 2
Joined: Fri Mar 28, 2014 12:12 pm

Re: 11461 - Square Numbers

Post by MikhailVladelin » Fri Mar 28, 2014 10:35 pm

brianfry713 wrote:That is AC code.
AC means accepted ? i'm getting wrong answer all the time :(

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11461 - Square Numbers

Post by brianfry713 » Mon Mar 31, 2014 11:14 pm

I just submitted that code you posted and got AC.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

11461 - Square Numbers

Post by Shahidul.CSE » Tue Jul 15, 2014 9:54 pm

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;
}
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

Post Reply

Return to “Volume 114 (11400-11499)”