Input:
Code: Select all
6
1
31727
490
407
677
29070
0
Code: Select all
2.535463
Moderator: Board moderators
Code: Select all
6
1
31727
490
407
677
29070
0
Code: Select all
2.535463
Code: Select all
Silly Mitake
Anyway AC now
Code: Select all
removed after AC..
Good luckAnswers must be rounded to six digits after the decimal point.
Code: Select all
Removed after accepted
you have an integer division, which rounds the result of division down to the nearest integer.double expected_pi = sqrt(6*npairs/compta);
Code: Select all
double expected_pi = sqrt(6*npairs/(double)compta);
or:
double expected_pi = sqrt(6.0*npairs/compta);
Code: Select all
//code removed after AC
Oh got AC ........brianfry713 wrote:On my machine your code prints 0.000000 for the first sample input. Your printf is using %Lf or long double, but sqrt returns a %lf or double.
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,a[50],d,temp,N,t;
while(1)
{
d=0,t=0;
scanf("%d",&N);
if(N==0)
break;
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if((a[i]%a[j]!=0))
{
if((a[i]%2!=0)||(a[j]%2!=0))
d++;
}
t++;
}
}
if(d==0)
printf("No estimate for this data set.\n");
else
printf("%.6lf\n",sqrt((6*t)/d));
}
return 0;
}
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,a[50],d,temp,N,t;
while(1)
{
d=0,t=0;
scanf("%d",&N);
if(N==0)
break;
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if((a[i]%a[j]!=0))
{
if((a[i]%2!=0)||(a[j]%2!=0))
d++;
}
t++;
}
}
if(d==0)
printf("No estimate for this data set.\n");
else
printf("%.6lf\n",sqrt((6*t)/d));
}
return 0;
}