hdu 5317 合数分解+预处理】的更多相关文章

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…
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1999    Accepted Submission(s): 689 Problem Description Long long ago, there was an ancient rabbit kingdom in the forest. Every ra…
Cards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 72 Problem Description Given some cards each assigned a number, you're required to select EXACTLY K cards amo…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 40    Accepted Submission(s): 22 Problem Description Given two positive integers G and L, could you tell me how many solutions of (x,…
题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R),只需要求出它们在 1~7 的范围内的数量,然后暴力求出 gcd 即可.因为符合递增,可以设一个结点 struct { v[8]; } 记录 1~7 的数量,结点间可以相加减,也就可以用前缀和的思想去做(其实我也是看了别人的题解才明白这种思想,一开始用二分不是超时就是 wa 了,不过我竟发现自己手写的二分比…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2151    Accepted Submission(s): 955 Problem Description Given two positive integer…
题意:x可以表示为bp, 求这个p的最大值,比如 25=52, 64=26,  然后输入x 输出 p 就是一个质因子分解.算法.(表示数据上卡了2个小时.) 合数质因子分解模板. ]; ]; ; ;n!=;++i) { ) { num[cnt]=i; ){ind[cnt]++;n/=i;} cnt++; } )break; } ){num[cnt]=n; ind[cnt++]=;} 两种方法: 方法一:时间最坏的时间复杂度是(大概10^8*n)就是这种方法,数据卡了很久,如果数据再给狠一点肯定不…
题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: ; ans != ; ++i) { ) { num[cnt] = i; ; ){ ++k; ans /= i; } index[cnt++] = k; } )break; } ){ num[cnt] = ans; index[cnt++] = ; } 然后,我自己写了个快速幂 快速幂的模板: ll pow(ll a, ll n) { ll res;…
比赛链接:传送门 题目大意: 一只青蛙在长度为N的字符串上跳跃,“R”可以跳上去,“P”不可以跳上去. 字符串是环形的,N-1和0相连. 青蛙的跳跃距离K的取值范围是[1, N-1],选定K之后不可改变. 要求青蛙最后能跳回起点(起点可以是0-N-1的任意一个位置),问K的取值有多少种选择. 3≤N≤105. 思路: 考虑到如果gcd(N, K) = g,则从起点开始跳的话,所有经过的点都是g的倍数,而且每个g的倍数都会经过. 所以只要考虑从任意一个点i开始,步长为g地跳,能不遇见"P"…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4568 思路:首先spfa预处理出每对宝藏之间的最短距离以及宝藏到边界的最短距离,然后dp[state][u]表示当前在点u,状态为state的最短距离,然后更新就行. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue&g…
思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> #include<queue> #include<map> #include<cstring> using namespace std; ; const int inf = 2.1e9; ; ; ; ][]; int Head[maxn]; int viss[maxn];…
就是输出n时,莫比乌斯函数的值.直接将n唯一分解即可. 思路:筛出105以内的素数,因为109开方,105就差不多.当一个大数还没有被1000个素数分解,那么这个数基本上可以认为是素数(为合数为小概率了).使用欧拉筛筛出105以内的素数,然后枚举素数试除即可 ac代码: #include<cstdio> #include<cstring> #define maxn int(1e5) #define ll long long int prime[maxn]; bool vis[max…
题目链接: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…
题意:求n是否只有4个因子,如果是就输出除1外的所有因子. 模板题,就不排版了 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> #include<ctime> using namespace std; #define MO…
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 gradual…
题目链接: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…
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent…
http://acm.hdu.edu.cn/showproblem.php?pid=5084 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每个值),即: ans[x][y] = t[y] * t[2*n - 2 - x] +....+ t[y + n - 1]*t[n - 1 - x] 每一对的和为定值2*n-2-x-y,然后就是求每对i+j的前缀和(所有i+…
1801: Mr. S’s Romance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 15  Solved: 5[Submit][Status][Web Board] Description Mr. S is a young math professor who is famous for being crazy about collecting prime numbers. Once he met a number, he would fir…
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…
Function The shorter, the simpler. With this problem, you should be convinced of this truth.      You are given an array AA of NN postive integers, and MM queries in the form (l,r)(l,r). A function F(l,r) (1≤l≤r≤N)F(l,r) (1≤l≤r≤N) is defined as: F(l,…
要从0,0 点 跑到m,n点  路上会有k个堡垒发射子弹.有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒 能够上下左右或者站着不动 每步都须要消耗能量  一共同拥有eng个能量 先预处理出地图 用三维数组表示mp[x][y][time] time表示该时间的地图上储存不能走的点 然后就是普通BFS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <…
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....因为…
Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 541    Accepted Submission(s): 141 Problem Description The students of the HEU are maneuvering for their military training. The red army…
题意: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…
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^13个因子 即8000多因子 所以每次可以递归暴力寻找一个因子,然后选好了以后,看唯一分解不同种素数还有哪种没有用,符合条件的只能用这些没有用过的,然后直接统计 注:由于最终每个对都被统计了两次,所以/2,由于本身也算一对,所以+1 代码: #include <cstdio> #include &…
题目链接:传送门 题目: B. Math time limit per test second memory limit per test megabytes input standard input output standard output JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is a…
这里贴个模板吧.反正是不太理解 看原题就可以理解用法!! #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <map> using namespace std; #define Times 10 typedef __int64 LL; map<LL,int>m; LL…