zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ

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


    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
     

     

    Author
    ZSTU
     

     

    Source
     
    解题:打表。。。学习了Crazyacking的写法
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1000005;
     4 
     5 int sum[maxn][8],kinds[maxn];
     6 bool np[maxn];
     7 void init() {
     8     for(int i = 2; i < maxn; ++i)
     9         if(!np[i]) {
    10             for(int j = i; j < maxn; j += i) {
    11                 np[j] = true;
    12                 ++kinds[j];
    13             }
    14         }
    15     for(int i = 1; i < maxn; ++i)
    16         for(int j = 7; j > 0; --j)
    17             sum[i][j] = kinds[i] == j;
    18     for(int i = 1; i < maxn; ++i)
    19         for(int j = 7; j > 0; --j)
    20             sum[i][j] += sum[i-1][j];
    21     //记录1到上界含有j个不同素因子的数的个数
    22 }
    23 int main() {
    24     int kase,a,b;
    25     init();
    26     scanf("%d",&kase);
    27     while(kase--) {
    28         scanf("%d%d",&a,&b);
    29         for(int i = 7; i > 0; --i) {
    30             if(sum[b][i] - sum[a-1][i] > 1) {
    31                 printf("%d
    ",i);
    32                 break;
    33             }
    34         }
    35     }
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    音频文件的属性
    判断UITextField.text是否为空(转)
    digital audio properties
    对scrollView的属性contentSize contentOffset contentInset个人理解
    OC定义变参函数
    va_list、va_start、va_arg、va_end的原理与使用(转载)
    游标笔记
    oracle中删除重复数据
    IIS无法启动,错误代码127[转自Alibaba DBA Team]
    推进游标是Fetch不是Petch!~!
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4695353.html
Copyright © 2011-2022 走看看