zoukankan      html  css  js  c++  java
  • HDU5317——素数筛——RGCDQ

    Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (Li<jR)

     

     

    Input
    There are multiple queries. In the first line of the input file there is an integer T indicates the number of queries.
    In the next T lines, each line contains L, R which is mentioned above.

    All input items are integers.
    1<= T <= 1000000
    2<=L < R<=1000000
     


    Output
    For each query,output the answer in a single line. 
    See the sample for more details.
     


    Sample Input
    2 2 3 3 5
     


    Sample Output
    1 1
     


    Author
    ZSTU
     


    Source
     
    /*素数筛
    然后对所有情况讨论
    */
    
    
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    int flag[1000005];
    int cout[1000005];
    int sum[1000005][10];
    int res[10];
    void inti()
    {
        for(int i = 2; i <= 1000000; i++){
            if(!flag[i]){
                for(int j = i;j <= 1000000; j+=i){
                    flag[j] = 1;
                    cout[j]++;
                }
            }
        }
        for(int i = 0; i <= 7; i++){
            for(int j = 2; j <= 1000000; j++){
                sum[j][i] = sum[j-1][i] + (cout[j] == i + 1);
            }
        }
    }
    
    
    int main()
    {
    inti();
    int T;
    scanf("%d", &T);
    int L, R;
    while(T--){
        scanf("%d%d", &L,&R);
        int ans = 1;
        for(int i = 0 ; i <= 7; i++)
            res[i+1] = sum[R][i] - sum[L-1][i];
            if(res[2] + res[4] + res[6] >= 2) ans = 2;
            if(res[3] + res[6] >= 2) ans = 3;
            if(res[4] >= 2) ans = 4;
            if(res[5] >= 2) ans = 5;
            if(res[6] >= 2) ans = 6;
            if(res[7] >= 2) ans = 7;
            printf("%d
    ", ans);
    }
    return 0;
    }
    

      

  • 相关阅读:
    带密钥的sha1加密
    单调队列优化和二进制优化的多重背包模板
    HDU6424 Rikka with Time Complexity
    HDU6415 Rikka with Nash Equilibrium
    BZOJ1012: [JSOI2008]最大数maxnumber
    BZOJ2660: [Beijing wc2012]最多的方案
    读入优化和输出优化模板
    BZOJ1089: [SCOI2003]严格n元树
    2018 “百度之星”程序设计大赛
    JavaScript事件代理和委托(Delegation)
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4694183.html
Copyright © 2011-2022 走看看