(有点递归的感觉)RGCDQ--hdu--5317】的更多相关文章

题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R),只需要求出它们在 1~7 的范围内的数量,然后暴力求出 gcd 即可.因为符合递增,可以设一个结点 struct { v[8]; } 记录 1~7 的数量,结点间可以相加减,也就可以用前缀和的思想去做(其实我也是看了别人的题解才明白这种思想,一开始用二分不是超时就是 wa 了,不过我竟发现自己手写的二分比…
RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2818    Accepted Submission(s): 1108 Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and m…
题目链接:pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317 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…
RGCDQ Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status 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 Ra…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5317 题意:F(x) 表示x的不同质因子的个数结果是求L,R区间中最大的gcd( F(i) , F(j) ),i.j在L,R区间内. 思路:因为2<=L < R<=1000000,所以他们的质因子最多的个数也就7个,也就是说1<=F(x)<=7,因为要求最大的GCD,所以只要知道在L,R区间内每个F(x)的情况就可以知道结果. 代码: #include <stdio.h&g…
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…
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 mo…
题意:从1~1000,000的每个自然数质因子分解,不同因子的个数作为其f 值,比如12=2*2*3,则f(12)=2.将100万个数转成他们的f值后变成新的序列seq.接下来T个例子,每个例子一个询问区间seq[L,R].问该子序列中任意两个不同下标的数,他们的GCD值最大为多少? 思路: (1)质因子分解,用筛法先将质数先全部出来. (2)对每个自然数求其f值,即将其质因子分解后的不同因子个数,作为seq序列. (3)扫一遍seq,用另一个数组记录下标i之前有多少个1.2.3.4....因为…
题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少. 解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计前i个数中每个f(i)出现的次数,当询问l和r时,用num[r] - num[l - 1],得到这一区间内的结果,然后讨论一下,如果出现过6和3则答案可能为3,如果出现过4和2则答案可能为2,如果某数字出现两次及以上则答案可能是这个数字,以上几种情况取最大值,即为答案. 代码: #include<s…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5317 感觉好神奇呀,一堆数在一起可以找到规律,学长讲完后,觉得自己是如此的so young f[x]不超过7的 代码: #include<algorithm> #include<stdio.h> #include<stack> #include<string.h> using namespace std; #define lson r<<1 #de…