Problem Type : Number Theory
#include<stdio.h>
#include<math.h>
int gcd(int i,int j)
{
int temp ,gcd;
while(j!=0)
{
temp = j;
j = i%j;
i= temp;
}
return i;
}
int main()
{
int n,arr[10000],i,j,sum,cou,con=0,odd=0,p,total;
double ans ,s;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
con = (n*(n-1))/2;
cou =0;
for(i=1; i<=n; i++)
{
scanf("%d",&arr[i]);
if(arr[i]%2==0)
{
cou++;
}
}
if(cou==n)
printf("No estimate for this data set.\n");
else
{
p=0;
for(i=1; i<=n; i++)
{
for(j=i+1; j<=n; j++)
{
sum=gcd(arr[i],arr[j]);
if(sum==1)
{
p++;
}
}
}
if(p==0)
{
printf("No estimate for this data set.\n");
}
else if(p!=0)
{
s=sqrt((6*con)/(p*1.0));
printf("%.6lf\n",s);
}
}
}
return 0;
}
#include<stdio.h>
#include<math.h>
int gcd(int i,int j)
{
int temp ,gcd;
while(j!=0)
{
temp = j;
j = i%j;
i= temp;
}
return i;
}
int main()
{
int n,arr[10000],i,j,sum,cou,con=0,odd=0,p,total;
double ans ,s;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
con = (n*(n-1))/2;
cou =0;
for(i=1; i<=n; i++)
{
scanf("%d",&arr[i]);
if(arr[i]%2==0)
{
cou++;
}
}
if(cou==n)
printf("No estimate for this data set.\n");
else
{
p=0;
for(i=1; i<=n; i++)
{
for(j=i+1; j<=n; j++)
{
sum=gcd(arr[i],arr[j]);
if(sum==1)
{
p++;
}
}
}
if(p==0)
{
printf("No estimate for this data set.\n");
}
else if(p!=0)
{
s=sqrt((6*con)/(p*1.0));
printf("%.6lf\n",s);
}
}
}
return 0;
}
No comments:
Post a Comment