1. C, Evgeni Pavlidis


/**
* ACM programming Contest WS 08/09
* UVa Status: accepted
* Run Time: 0.320
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <stdio.h>
#include <math.h>

int number[50];
int numbers;

int main()
{
while(1)
{
int counter = 0;
int whole = 0;

scanf("%d\n",&numbers);
if(numbers == 0)
return 0;

int i;
for(i=0; i < numbers; i++)
scanf("%d\n", &number[i]);

int x,y;
for(x=0; x < numbers; x++)
for(y=x+1; y < numbers; y++, whole++)
if(gcd(number[x],number[y]) == 1)
counter++;


if(counter == 0)
printf("No estimate for this data set.\n");
else
printf("%1.6f\n", sqrt(6.0*whole/counter));
}
}

int gcd(int m, int n)
{
if(m == 0)
return n;

while(n != 0)
{
if(m < n)
{
int aux = n;
n = m;
m = aux;
}

m = m - n;
}
return m;
}


2. C, ****


/**
* ACM programming Contest WS 08/09 "412 - Pi"
* Accepted Run Time 0.310
* @author ****, Nov. 2008
* In Vorlesung besprochen..
*/

#include <stdio.h>
#include <math.h>

int gcd(int a, int b){
while(a != b)
if(a>b) a -= b;
else b -= a;
return a;
}

int main(){
int rez;
int a[100], i, j, n;
double aux;
while(scanf("%d\n", &n)>0&&n){
rez = 0;
for(i=0; i<n; i++) scanf("%d\n", &a[i]);
for(i=0; i<n; i++)
for(j=i+1; j<n; j++)
if(gcd(a[i], a[j])==1) rez++;
if(rez){
aux = sqrt( 6.0/(float)rez*(float)(n*(n-1)/2) );
printf( "%f\n", aux );
}
else
printf("No estimate for this data set.\n");
}
return 0;
}