zoukankan      html  css  js  c++  java
  • HDU-5317

    RGCDQ

    Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 698    Accepted Submission(s): 328


    Problem Description
    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
     
    Source
     
    /**
        题意:给出一个区间,然后求区间的数的质因子个数之间的最大公约数
        思路:枚举2~N之间的每个数的质因子的个数,计算L ~ R 之间的数的
              质因子的个数,因为之前打过表,2~N之间的最大的质因子个数是7
              所以,计算L ~ R 之间的1~7出现的次数,然后进行统计枚举,
              被自己蠢dao了
    **/
    #include <iostream>
    #include <cmath>
    #include <algorithm>
    #include <stdio.h>
    #include <string.h>
    #define maxn 1000000+10
    using namespace std;
    int num[maxn];
    int sum[maxn][10];
    int mmap[10];
    int temp[20];
    void init()
    {
        memset(num,0,sizeof(num));
        memset(sum,0,sizeof(sum));
        for(int i=2;i<maxn;i++)
        {
            if(num[i]) continue;
            num[i] = 1;
            for(int j=2;j*i<maxn;j++)
            {
                num[j*i] ++;
            }
        }
        sum[2][1] = 1;
        for(int i=3;i<maxn;i++)
        {
            for(int j=1;j<=7;j++)
            {
                sum[i][j] = sum[i-1][j];
            }
            sum[i][num[i]]++;
        }
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int T;
        scanf("%d",&T);
        init();
        while(T--)
        {
            int left,right;
            scanf("%d %d",&left,&right);
            int cet = 0;
            memset(temp,0,sizeof(temp));
            memset(mmap,0,sizeof(mmap));
            for(int i=1;i<=7;i++)
            {
                mmap[i] = sum[right][i] - sum[left][i];
                if(num[left] == i)mmap[i]++;
                if(mmap[i] >= 2)
                {
                    temp[cet++] = i;
                    temp[cet++] = i;
                }
                else if(mmap[i] == 1)
                    temp[cet++] = i;
            }
            int mmax = 0;
            for(int i=0;i<cet;i++)
            {
                for(int j=i+1;j<cet;j++)
                {
                    mmax = max(mmax,__gcd(temp[i],temp[j]));
                }
            }
            printf("%d
    ",mmax);
        }
        return 0;
    }
  • 相关阅读:
    js/jquery/插件表单验证
    超级英雄在中国香港的平凡生活
    Nginx简单配置几个基于端口的虚拟主机
    Nginx配置简单基于域名的虚拟主机
    反驳关于“码农”的说法
    Nginx配置简单负载均衡
    Nginx Windows版安装及域名绑定
    转载:Java对Base64处理的细节
    转载:Base64编解码介绍
    多层If语句 和 表格驱动 的对比
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4684579.html
Copyright © 2011-2022 走看看