Page 7 of 14

Posted: Thu Jun 22, 2006 7:07 pm
by Dickon
thank you very much , i will try it.

Re: 10200(time limited~help)

Posted: Fri Jun 23, 2006 4:00 am
by Dickon
thank for your suggestion,i get AC.

Posted: Tue Jul 11, 2006 7:08 pm
by vinit_iiita
TLE :-? :-? :-? why????????????

Code: Select all

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
bool prime(long long int j)
{    bool fl=true;
     if(j==0 && j==1)
     return true;
     else
     {
     for (long long int t=2;t<=sqrt(j);t++)
     {
     if(j%t==0)
     {        
        fl=false;
              }
              }
     if(fl==false)
     return false;
     if(fl==true)
     return true;
     }
     }
int main()
{
    int a,b,k=2;
    int v[10001];
    v[0]=0;v[1]=1;
    for (int h=3;h<=10001;h=h+2)
    {
        if(prime(h)==true)
        {
         v[k]=h;
         k++;
         }
         }
    while (cin>>a>>b)
    {
           bool flag1=false,flag2;
           int c2=0;        
           
              for (int i=a;i<=b;i++){flag2=true;   
               long long int m=i*i+i+41;
               
               for(int q=2;q<k && v[q]<sqrt(m);q++)
               {if(m%v[q]==0)
                flag2=false;
               }
               if (flag2==true && i!=40)
               c2+=1;
               
               }
               double pr;
               pr=(double(c2)/double(b-a+1))*100.0;
               cout<<setiosflags(ios::fixed)<<setprecision(2)<<pr<<endl;
               }
               return 0;
               }
help me out.......plz....[/b]

10200 WA

Posted: Thu Aug 17, 2006 2:09 pm
by Tahasin
#include<stdio.h>
#include<math.h>
main()
{
int a,b,c,k[10000],i,j,t,prime,count=0,m,n,counter;float s,p,q;
for(i=0;i<=10000;i++)
{
prime=1;
a=i*i+i+41;b=sqrt(a);
for(j=2;j<=b;j++)if(a%j==0)prime=0;
if(prime){k[count]=i;count++;printf("%d,",i);}
}
printf("\n\n%d",count);
/*while((scanf("%d%d",&m,&n))==2)
{
counter=0;
for(i=m;i<=n;i++)
{
for(j=0;j<count;j++){if(i==k[j]){counter++;break;}}
}s=n-m+1;p=counter;q=(counter/s)*100;
printf("%.2f\n",q);
}*/
return 0;
}

whats the prob?

Posted: Sun Oct 01, 2006 1:07 pm
by rushafi
i am getting WA over and over again. I've tested some of Minilek's cases and found some fault. Actually the answer is too near. I am unable to find the problem so far.

A little help will be very much appriciated.

here is 3 test cases 4 xample:

3957 8978
8138 9707
843 8651


my ans:

38.53
37.07
40.40


minilek's ans:

38.51
37.01
40.39


and my code:

#include<stdio.h>
#include<math.h>

int count[10005];

int main(){
int flag,total,temp,a,b;
long prime,z;
double ans;
count[0]=1;
for (int i=1;i<10005;i++){
prime=i*i+i+41;
flag=1;
if (prime%2==0) flag=0;
else {
z=ceil(sqrt(prime));
for(int c=3;c<=z;c+=2){
if (prime%c==0){
flag=0;
break;
}
if (flag==0) break;
}
}
count=count[i-1]+flag;
}
while(scanf("%d %d",&a,&b)==2){
if ((count==count[a]) && (count[a]==count[a-1])) temp=0;
else{
total=b-a+1;
temp=count-count[a]+1;
}
ans=(temp*100.)/total;
printf("%.3lf\n",ans);
}
return 0;
}

Re: whats the prob?

Posted: Sun Oct 01, 2006 2:34 pm
by little joey
Please use code tags! This is much better for the reader of your message:

Code: Select all

#include<stdio.h>
#include<math.h>

int count[10005];

int main(){
	int flag,total,temp,a,b;
	long prime,z;
	double ans;
	count[0]=1;
	for (int i=1;i<10005;i++){
		prime=i*i+i+41;
		flag=1;
		if (prime%2==0) flag=0;
		else {
			z=ceil(sqrt(prime));
			for(int c=3;c<=z;c+=2){
				if (prime%c==0){
					flag=0;
					break;
				}
			if (flag==0) break;
			}
		}
		count[i]=count[i-1]+flag;
	}
	while(scanf("%d %d",&a,&b)==2){
		if ((count[b]==count[a]) && (count[a]==count[a-1])) temp=0;
		else{
			total=b-a+1;
			temp=count[b]-count[a]+1;
		}		
		ans=(temp*100.)/total;
		printf("%.3lf\n",ans);
	}
	return 0;
}

Posted: Thu Nov 16, 2006 3:06 pm
by IRA
Does the problem be rejudged?

Posted: Thu Nov 16, 2006 4:10 pm
by little joey
Yes, it did been.
The judge now only accepts the correct answer.

Posted: Thu Nov 16, 2006 7:34 pm
by abhi
i am sure that my code is right . but i get WA plz help me out ...

Code: Select all

# include <stdio.h>

int prime[10010];

void genprime()
{
    int i,j;
    
    for(i=0;i<=10010;i++)   prime[i]=i;
    
    prime[0]=prime[1]=0;
     
    for(j=4;j<=10010;j+=2)  prime[j]=0;
    
    for(i=3;i*i<=10010;i+=2)
        if(prime[i])
            for(j=i*i;j<=10010;j+=i)
                prime[j]=0;
}

int isprime(int n)
{
   int i,j;
   
   
   if(n<2 || n%2 == 0 || n%5 == 0)  return 0;
   
   for(i=0;prime[i]*prime[i]<=n;i++)
    if(prime[i])
    if(n%prime[i] == 0)
        return 0;
        
    return 1;
}
        
int main()
{
    int  i,j,m,n;
    double count;
    int flag[10005]={0};
    
    genprime();
    
       for(i=0;i<=10000;i++){
            if(isprime(i*i+i+41))
                flag[i]=1; 
            }
    while(scanf("%d %d",&m,&n) == 2)
    {
        count = 0.0;
     
        
        for(i=m;i<=n;i++){
            if(flag[i])
                count++;
                                          
        }
                
        printf("%.2lf\n",(count/(n-m+1))*100);
    }
return 0;
}

Posted: Fri Nov 17, 2006 4:52 am
by IRA
My previous code is accept.
When I submit it again,it got WA.
I don't know what change in the problem.
I test many test data then still got WA.

Posted: Fri Nov 17, 2006 4:55 am
by Darko
Try adding EPS to the result before printing. It fixed my solution.

Posted: Fri Nov 17, 2006 5:21 am
by IRA
Darko wrote:Try adding EPS to the result before printing. It fixed my solution.
Thank you!
I set EPS to 10^-9 and got AC!

Posted: Sun Nov 19, 2006 2:50 am
by shanto86
AC

Posted: Sun Nov 19, 2006 3:52 am
by minskcity
little joey wrote:Yes, it did been.
The judge now only accepts the correct answer.
Also, it now rejects correct answers if you round them with cin.

I believe any problem that asks to ouput 'up to some precision' should specify how to round or have a special correction program :evil:

Posted: Sun Nov 19, 2006 8:30 am
by little joey
Only if the answer is the result of floating point calculations. In this problem you can calculate the correct answer using integers only, so there is no need for a special corrector.