thanks a lot UFP2161!!!!!(I don't understand your nick)
I finally got AC!!
I just forgot some stupid part of the problem!!
Thanks again!!!!
wish you good luck!!!
byee
int gcd(int p,int q)
{
if (q > p) return(gcd(q,p));
if (q == 0) return(p);
return( gcd(q, p % q) );
}
Change the call accordingly.
Then, remove the check for repeated numbers.
Further, get rid of the extra variables x[1] and x[2] and change 6 to 6.0
Then, remove the various increments for total, just change it to
total=n*(n-1)/2;
*whew* That should do it
Someone can help me? I can't see where is the problem but the systems says WA.
-------------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
typedef struct {
int dim;
int v[50];
} set;
int readinput (set f[]) {
int i=0, j=0;
while(f.dim!=0) {
scanf("%d",&f.dim);
if (f.dim!=0) {
for (j=0;j<f.dim;j++) {
scanf("%d",&f.v[j]);}
i++; }}
return i;}
int cmp (int a, int b) {
int i; double r=0;
if (a>b && b!=1) {
for (i=2;i<=b;i++) {
if (a%i==0 && b%i==0 ) {
r= 1; } }
}
else if (b>a && a!=1) {
for (i=2;i<=a;i++) {
if (a%i==0 && b%i==0 ) {
r= 1; } }
}
else if (a==b ) {
r= 1; }
return r;
}
double sum (int n) {
int i, r=0;
for (i=1; i<n;i++) {
r=r+i; }
return r; }
void main() {
int i, max, j, k;
double r2;
set f[50];
double count[50];
double r;
max = readinput (f);
for (i=0; i<max; i++) {
count=0;
for (j=0; j<f.dim; j++) {
for (k=0; k<f.dim; k++) {
if (cmp( f.v[j], f.v[k]) ==0 ){
count [i] ++; } }
}
if (count [i]>0) {
r = sqrt ( 6*(2*sum(f[i].dim)) / (count[i]) );
printf ("%.6lf\n", r); }
else
printf ("No estimate for this data set.\n") ;
}
double pairs = n*(n-1)/2;
double pi = sqrt(6*pairs/count);
where pairs are the maximum quantity of pairs and count is amount;) of pairs in which greatest common divisor is 1
and your function may be done much easier(actually I dont understand what you've tried to do there, it could be as well as void, couse it returns value to nothin', but your prog succeded in/out, so nevermind)
and sqrt() in <cmath> sometimes calculate incorrect answers(dont know why),so you'd better not to declare "namespace" standard, just change it to <math.h> instead of <cmath> and remove "using namespace std;"
(stdio also)
#include<stdio.h>
#include<math.h>
int _fact(long int a,long int b)
{
long int i,j;
for(i=2;i<=a || i<=b;i++)
{
if(a%i==0 && b%i==0)
return 1;
}
return 0;
}
int main(void)
{
long int N,count=0,total=0,i,j;
long int arr[50];
while(1)
{
scanf("%ld",&N);
if(N==0)
break;
for(i=0;i<N;i++)
scanf("%ld",&arr[i]);
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
total++;
if(!_fact(arr[i],arr[j]))
count++;
}
}
/* printf("%ld %ld\n",total,count); */
if(count==0)
printf("No estimate for this data set.\n");
else
printf("%.6f\n",sqrt((total*6)/count));
count=0;
total=0;
}
return 0;
}