Page 3 of 6
10110....WA
Posted: Tue Mar 23, 2004 7:23 am
by rlatif119
This is one of the easy problem as far as i know........is it really????.....hmmmmm......but it always gives me wrong answer.......why???[c]
#include<stdio.h>
#include<math.h>
main()
{
long n,s;
while(1)
{
scanf("%ld",&n);
if(n==0)
break;
s = (long)sqrt(n);
if(s*s==n)
printf("yes\n");
else
printf("no\n");
}
}[/c]
[/c]
right you are
Posted: Tue Mar 23, 2004 7:49 am
by sohel
Hello Rlatif,
Here is a quote from the problem statement:
The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1.
long can not handle inputs more that
2^31-1.
Either use unsigned long or long long.
Otherwise your code seems to be correct.

Posted: Tue Mar 23, 2004 11:20 am
by rlatif119
I've changed my datatype to unsigned long......but its still WA.....anyway thanks for your reply.
Posted: Wed Mar 24, 2004 10:40 am
by Subeen
rlatif119, I think you are making any mistake in your submission. If you change the datatype into unsigned long then your program gets accepted. You have to use %lu for unsigned data type and do not typecast into long. ( you don't need any typecast here )
Posted: Wed Mar 24, 2004 7:54 pm
by rlatif119
Thanks a lot Subeen.......Oh i can't imagine i had done a silly mistake like this........i didn't change the format........oh.....i can't imagine......isn't it a silly mistake.
Any way.......Thanks again.
10110 light more light runtime error
Posted: Sat Aug 07, 2004 8:05 am
by UOB
hi every body,
i thankful if anybody help me to fix this problem
i submitted my code into the judge amd he gave me a runtime error
please help me
[code]
#include <iostream>
using namespace std;
void Switch( int &state )
{
if ( state == 1 )
state = 0;
else
state = 1;
}
int main()
{ int a[10],i=0,j,size;
int bulb;
char *str[2]={ "no","yes"};
char* out[10];
cin >> a[0];
while(a[i]!=0)
{ i++;
cin>>a[i];}
size=i;
i=0;
while ( i != size ) {
bulb=a[i] ;
int state = 0;
for ( j = 1; j <= bulb; j++ )
if ( bulb % j == 0 ) {
Switch( state );
if ( j * j != bulb )
Switch( state );
}
*(out+i)=*(str+state);
i++;
}
for( i=0;i<size;i++)
cout<<out[i]<<endl;
return 0;
}
another question is that how can i get the compiler that the judge use it
can anyone give me a site i can downloaded??
[/code]
Posted: Sat Oct 30, 2004 7:39 pm
by Piers Kennedy
Actually it isn't quite right.
The input requires integers that are less than or equal to 2^32-1 so you must use unsigned int.
This is my accepted code. Just look... so small and so simpl
Posted: Sat Dec 18, 2004 8:12 pm
by Niaz
This is my accepted code. Just look... so small and so simple.

I hope, it will inspire you to think in a simple way.
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
long double num,b;
long a;
while(1)
{
scanf("%Lf",&num);
if(num==0)
break;
a= some_function(num);
//calling a commonly used
//builtin C function.
b= some_function(num);
// same function again.
if(a==b)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
Posted: Sat Dec 18, 2004 9:00 pm
by Mohammad Mahmudur Rahman
Also you can try to work out for the first few numbers to find out which of them leads to an on bulb. I think u'll need no more than 15-20 cases to get the idea.
Posted: Mon Dec 20, 2004 12:06 pm
by Rocky
GOOD Reply NIAZ
I think that is the best solution for the problem.\
BY the Way
GOOD LUCK
10110 Presentation Error
Posted: Sun May 29, 2005 1:13 am
by CodeJerk
Hi
I get a PE with this program. Its driving me crazy now. Could some1 plz tell me why i m getting it. Thanks in advance.
Code: Select all
#include <iostream.h>
#include <math.h>
int main()
{
int flag = 1;
unsigned long i;
while (flag)
{
cin >> i;
if (i != 0)
{
double value = i;
double sqrtvalue = sqrt(value);
if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square
cout<<"yes\n";
else cout<<"no\n";
}
else flag=0;
}
return (0);
}
Ah....
Posted: Sun May 29, 2005 7:19 am
by sohel
Well, that's odd..
.. I just submitted your code and got AC without presentation error.

Doesnt even Compile!!!
Posted: Sun May 29, 2005 8:40 am
by CodeJerk
Actually I was trying my code at the Programming Challenges website, where I was repeatedly getting a PE.
After seeing that the code was getting accepted at the online-judge, I did try mailing it. I mailed the following :-
Code: Select all
/* @JUDGE_ID: 62454TK 10110 C++ */
/* @BEGIN_OF_SOURCE_CODE */
#include <iostream.h>
#include <math.h>
int main()
{
int flag = 1;
unsigned long i;
while (flag)
{
cin >> i;
if (i != 0)
{
double value = i;
double sqrtvalue = sqrt(value);
if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square
cout<<"yes\n";
else cout<<"no\n";
}
else flag=0;
}
return (0);
}
/* @END_OF_SOURCE_CODE */
And the program doesn't even compile now!!!!
What has gone wrong? This is the first time I am using the online-judge, so maybe I am doing something that is downright stupid. Could you please point it out, and help me out of this mess.
Thanks
Posted: Sun May 29, 2005 10:53 am
by neno_uci
After trying a lot of changes to your program, all the solutions I sent were PE too, so don't worry, your algorithm is correct and my AC code here got PE there too..., best regards,
Yandry.

10110
Posted: Mon May 15, 2006 11:05 am
by eyeabhi
I think if the number of bulbs is a perfect square, then answer is yes, otherwise no. Is my guess incorrect?
I get WA every time. Plz anyone tell me whts wrong here?
I have solved the problem.