PersonalCorpus 版 (精华区)
Your C++ program has solved Ok the problem 412 (Pi)
in 1.040 seconds using as much as 408 kbytes of virtual memory.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
int gcd(int a, int b)
{
while (a!=b) {
if (a%b==0) return b;
a%=b;
if (b%a==0) return a;
b%=a;
}
return a;
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input412.txt","r",stdin);
freopen("c:\\uva\\output412.txt","w",stdout);
#endif
int i,j,n,sum;
int a[50];
scanf("%d\n",&n);
while (n!=0) {
sum=0;
for (i=0;i<n;i++) {
scanf("%d\n",&a[i]);
for (j=0;j<i;j++) if (gcd(a[j],a[i])==1) sum++;
}
if (sum==0) printf("No estimate for this data set.\n"); else
printf("%.6lf\n",sqrt((double)(3*n*(n-1))/(double)(sum)));
scanf("%d\n",&n);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:7.954毫秒