精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • 用c語言如何判斷素數(shù)

    用c語言如何判斷素數(shù)
    其他人氣:921 ℃時間:2020-03-04 05:26:50
    優(yōu)質(zhì)解答
    0.210秒,用Miller-Ribin檢驗素數(shù)
    在oj上是15ms
    #include
    #include
    #include
    #include
    int a,b;
    int mpow( int s,int t,int m )
    {
    long long f,p;
    if ( t == 0 )
     return 1;
    f = mpow( s,t >> 1,m );
    if ( t & 1 )
    {
     p = s * f * f;
     return p % m;
    }
    p = f * f;
    return p % m;
    }
    int Miller_Ribin( int s )
    {
    int i,p;
    for ( i = 0; i < 3; i++ )
    {
     p = rand()% ( s - 2 ) + 2;
     if ( mpow( p,s - 1,s ) != 1 )
    break;
    }
    return i == 3;
    }
    void work( int c )
    {
    int p = ( c - 1 ) >> 1,i,j,s = 1,r,t1,t2;
    if ( c == 1 )
    {
     if ( a = 3 )
    printf("3\n");
     if ( a = 5 )
    printf("5\n");
     if ( a = 7 )
    printf("7\n");
     return ;
    }
    for ( i = 0; i < p; i++ )
     s *= 10;
    for ( i = 1; i < 10; i += 2 )
    {
     for ( j = 0; j < s; j++ )
    {
    r = i * s + j;
    t1 = j / 10;
    t2 = p - 1;
    while ( t2 )
    {
     r = r * 10 + ( t1 % 10 );
     t1 /= 10;
     t2--;
    }
    r = r * 10 + i;
    if ( r < a )
     continue;
    if ( r > b )
     return ;
    if ( Miller_Ribin( r ) )
     printf("%d\n",r);
    }
    }
    }
    int main( )
    {
    int s,e;
    srand( time( NULL ) );
    int i,p,c;
    // scanf("%d%d",&a,&b);
    a = 3; b = 1000000000;
    p = 1;
    c = 0;
    while ( p < a )
    {
     c++;
     p *= 10;
    }
    p /= 10;
    while ( p < b )
    {
     if ( c == 2 )
    printf("11\n");
     if ( c & 1 )
    work( c );
     c++;
     p *= 10;
    }
    printf("force program runs %.3lfs\n",clock( ) / (double)
    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點,以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權(quán)所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機版