10110  Light, more light
Moderator: Board moderators

 New poster
 Posts: 7
 Joined: Fri Mar 02, 2007 10:20 am
Re: WA in 10110
eyeabhi wrote: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?Code: Select all
deleted
I have solved the problem.
You try to solve it,
Its a very easy problem,how can u be student of BUET????????
Re: 10110  Light, More Light
here is my code
it gives WA
pls help...
it gives WA
pls help...
Code: Select all
import java.io.*;
class light
{
public static void main(String args[])throws Exception
{
DataInputStream dis= new DataInputStream(System.in);
String ans="";
int n;
boolean flag=false;
System.out.println("input:");
while(true)
{
n=Integer.parseInt(dis.readLine());
if (n==0)
break;
flag=false;
for(int i=1;i<=n;i++)
{ if(n%i==0)
flag=(flag==true)?false:true;}
if(flag==true)
ans="1"+ans;
else
ans="0"+ans;
}
System.out.println("output:");
for(int i=0;i<ans.length();i++)
{
if(ans.charAt(i)=='1')
System.out.println("yes");
else
System.out.println("no");
}
}
}
10110Light more Lightin C
When i submit this problem i getting TLE.Please help me!!
#include<stdio.h>
#include<math.h>
int main()
{
int t;
unsigned long int input;
double sq;
scanf("%d",&t);
while(t)
{
scanf("%lu",&input);
sq=sqrt(input);
if(sq*sq==input)
printf("NO");
else
printf("YES");
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
int t;
unsigned long int input;
double sq;
scanf("%d",&t);
while(t)
{
scanf("%lu",&input);
sq=sqrt(input);
if(sq*sq==input)
printf("NO");
else
printf("YES");
}
return 0;
}
Re: 10110  Light, More Light
you can use floor and ceil function to solve this problem.
i just use :
if (floor(sqrt(n))==ceil(sqrt(n)))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
and i accepted...
i just use :
if (floor(sqrt(n))==ceil(sqrt(n)))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
and i accepted...
Re: 10110Light more Lightin C
I found my mistake and gotAC.
10110 why WA? please any body help me
#include<iostream>
#include<math.h>
using namespace std;
int divisable(unsigned long int n);
int main()
{
unsigned long int n;
int c;
double db;
while((cin>>n)&&n!=0){
db=sqrt(n);
if(db*db!=n)
cout<<"no"<<endl;
else
cout<<"yes"<<endl;
}
return 0;
}
#include<math.h>
using namespace std;
int divisable(unsigned long int n);
int main()
{
unsigned long int n;
int c;
double db;
while((cin>>n)&&n!=0){
db=sqrt(n);
if(db*db!=n)
cout<<"no"<<endl;
else
cout<<"yes"<<endl;
}
return 0;
}
Re: 10110 why WA? please any body help me
I think changing "double db" with "unsigned long db" and "db=sqrt(n)" with "db=(unsigned long)sqrt(n)" will do. Hope you got AC by the time..
Re: 10110  Light, More Light
how ican avoid time limit exit ?any one help me please..........
#include<stdio.h>
long int n,i,k=0;
int main()
{
while (1)
{
k=0;
scanf("%d",&n);
if (n==0)
break;
for (i=1;i<=n;i++)
{
if (n%i==0)
k++;
}
if (k%2==0)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
#include<stdio.h>
long int n,i,k=0;
int main()
{
while (1)
{
k=0;
scanf("%d",&n);
if (n==0)
break;
for (i=1;i<=n;i++)
{
if (n%i==0)
k++;
}
if (k%2==0)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
Re: 10110  Light, More Light
hello nb2,
first of all, i think you should declare a bigger variable as long isn't sufficient enough to hold an integer of size (2^321) . . unsigned long will be enough.
2ndly, you are simulating the whole program where the problem is all about simple math! try checking whether the number is a perfect square . . if it is then the light will be turned on.
hope it helps
regards
sauro
first of all, i think you should declare a bigger variable as long isn't sufficient enough to hold an integer of size (2^321) . . unsigned long will be enough.
2ndly, you are simulating the whole program where the problem is all about simple math! try checking whether the number is a perfect square . . if it is then the light will be turned on.
hope it helps
regards
sauro
all that we see or seem is but a dream within a dream
Who is online
Users browsing this forum: No registered users and 1 guest