Пример #1
0
int main()
{
  	int n,x,y,temp;
  	std::vector<int>elem;
  	std::scanf("%d",&n);
  	while( n != 0 )
  	{
	  	x = y = 0;
    		for( int i = 0; i < n; i++ )
    		{
      			std::scanf("%d",&temp);
      			elem.push_back(temp);
    		}
    		for( size_t i = 0; i < elem.size(); i++ )
    		for( size_t j = i+1; j< elem.size(); j++ )
    		{
			if(common_factor(elem[i],elem[j])== 1)
	  			x++;
			y++;
    		}
    		if( x== 0 )
      			std::printf("No estimate for this data set.\n");
    		else
    			std::printf("%0.6lf\n",sqrt(6*y/static_cast<double>(x)));
    		elem.clear();
   		std::scanf("%d",&n);
  	}
  	return 0;
}
Пример #2
0
/*==================================================================*/
int
Csrc::gen_src_filter ( int source0, int target )
{
    int n;
    int ncutoff;
    int mem;
    int ntaps;
    int source;
    int source1, target1;
    int ncutoff1;

    source = source0;
    source1 = source;
    target1 = source;
    ntaps = compute_ntaps ( source, target );
    n = target / common_factor ( source, target );
    mem = n * ntaps;

    if ( source == target )
        src.ncase = 0;
    else if ( 2 * source == target )
        src.ncase = 1;
    else if ( source < target )
        src.ncase = 2;
    else if ( mem <= 780 )
        src.ncase = 3;
    else
        src.ncase = 4;

    if ( src.ncase == 4 )
    {
        source = cascade_factors ( source, target );
        if ( source <= 0 )
            return 0;   // fail
        target1 = source;
    }

    src.ntaps1 = compute_ntaps ( source1, target1 );
    src.n1 = target1 / common_factor ( source1, target1 );
    src.k1 = source1 / target1;
    src.m1 = ( src.n1 * source1 - target1 * src.n1 * src.k1 ) / target1;
    src.totcoef1 = src.ntaps1 * src.n1;
    ncutoff1 = ( int ) ( 0.90 * src.ntaps1 * target1 / source1 + 0.50 );
    if ( ncutoff1 > src.ntaps1 )
        ncutoff1 = src.ntaps1;

    src.ntaps = compute_ntaps ( source, target );
    src.n = target / common_factor ( source, target );
    src.k = source / target;
    src.m = ( src.n * source - target * src.n * src.k ) / target;
    src.totcoef = src.ntaps * src.n;
//ncutoff = 0.85*src.ntaps*target/source  + 0.50;
    ncutoff = ( int ) ( 0.90 * src.ntaps * target / source + 0.50 );
//ncutoff = (ncutoff & (~1)) | (src.ntaps & 1);
    if ( ncutoff > src.ntaps )
        ncutoff = src.ntaps;

/*--------------------------------------
//if( (src.n < 50) && (source > target) ) 
//if( (source > target) )
//if( src.ncase == 4 )
{ 
printf("\n%5d to %5d", source0, target);
printf(" ncase=%1d", src.ncase);
//if( src.ncase == 4 ) 
{
    printf("\n  %5d to %5d", source0, source);
    printf("  k+m/n  %1d %3d %4d", src.k1, src.m1, src.n1); 
    printf(" taps = %2d", src.ntaps1);
    printf(" ncoefs %5d", src.totcoef1);
    printf(" c/o = %2d", ncutoff1);
    printf("\n  %5d to %5d", source, target);
}
printf("  k+m/n  %1d %3d %4d", src.k, src.m, src.n); 
printf(" taps = %2d", src.ntaps);
printf(" ncoefs %5d", src.totcoef);
printf(" c/o = %2d", ncutoff);
  //printf(" minb %3d", src.minbuf);
}
------------------------------------*/

// init accum filter delta (down counter wrap if <= 0
    src.am = src.n;
    src.ic = 0; // init 
    src.minbuf =
        ( int ) ( 1152.0 * source0 / target + ( src.ntaps - 1 ) + 1 );
    if ( src.ncase == 4 )
        src.minbuf += ( 128 + 4 );
    src.am1 = src.n1;
    src.ic1 = 0;        // init 
    src.nbuf = 0;

// return failed if not enough memory
    if ( src.totcoef1 > ( sizeof ( src.coef1 ) / sizeof ( float ) ) )
        return 0;
    if ( src.totcoef > ( sizeof ( src.coef ) / sizeof ( float ) ) )
        return 0;

    gen_f ( src.coef1, src.ntaps1, ncutoff1, src.n1, src.m1 );
    gen_f ( src.coef, src.ntaps, ncutoff, src.n, src.m );
//for(i=0;i<n;i++) outf4(src.coef+i*src.ntaps, src.ntaps);

    return src.minbuf;
}
Пример #3
0
/*==================================================================*/
static int
cascade_factors ( int source, int target )
{
    int i;
    int cf;
    int s, t;
    int fs1, ft1;
    int fs2, ft2;
    int ntaps, ncutoff;
    int source2;
    int mem;

    if ( source <= target )
        return source;

    cf = common_factor ( source, target );
    s = source / cf;
    t = target / cf;

    ft1 = 0;    // init to eliminate compiler warning
    fs1 = 0;
    for ( i = 7; i < t; i++ )
    {
        if ( s != i * ( s / i ) )
            continue;
        if ( t != ( i + 1 ) * ( t / ( i + 1 ) ) )
            continue;
        fs1 = i;
        ft1 = i + 1;
        ft2 = t / ft1;
        source2 = ft1 * source / fs1;
        ntaps = compute_ntaps ( source2, target );
        mem = ntaps * ft2;
        if ( mem <= 780 )
            break;
    }

    if ( fs1 == 0 )
    {
        //printf("\n cascade fail");
        return 0;       // failed
    }

//printf("\n fs1 ft1 %3d %3d", fs1, ft1);

    fs2 = s / fs1;
    ft2 = t / ft1;
//printf("    fs2 ft2 %3d %3d", fs2, ft2);

    source2 = ft1 * source / fs1;
    ntaps = ( 12 * source2 + target / 2 ) / target;

    ncutoff = ( int ) ( 0.85 * ntaps * target / source2 + 0.50 );

//printf("\n stage 2  source %5d", source2);
//printf("   taps = %3d", ntaps);
//printf("   c/o  = %3d", ncutoff);
    mem = ntaps * ft2;
//printf("   mem  = %3d", mem);

    return source2;
}