Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:代码

Posted by 8013 at 2004-02-18 16:45:28 on Problem 1491
In Reply To:Re:??是精度太高了还是太低了? Posted by:hoho at 2004-02-18 16:14:24
# include<iostream.h>
# include<math.h>
# include<stdio.h>


long gcdhelp( long u,long v )
{
	if( u%v == 0 ){
		return v;
	}
	return gcdhelp( v,u%v );
}

long gcd( long u,long v )
{
	if( u > v ){
		return gcdhelp( u,v );
	}
	return gcdhelp( v,u );
}


void main( )
{
	int n;
	while( 1 ){
		cin>>n;
		long count = 0;
		if( n == 0 ){
			break;
		}
		int *a = new int[n];
		for( int i = 0;i < n;i ++ ){
			cin>>a[i];
		}
		for( i = 0;i < n - 1;i ++ ){
			for( int j = i + 1;j < n;j ++ ){
				if( gcd( a[i],a[j] ) == 1 ){
					count ++;
				}
			}
		}
		delete[] a;
		if( count == 0 ){
			cout<<"No estimate for this data set."<<endl;
		}
		else{
			long sum = 3*n*( n - 1 );
			double p = sum/1.0;
			p /= count;
			double pi = sqrt( p );
			printf("%.6f\n",pi);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator