hdu 5019(第K大公约数)】的更多相关文章

Revenge of GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2140    Accepted Submission(s): 596 Problem Description In mathematics, the greatest common divisor (gcd), also known as the greate…
__gcd-最大公约数 最大公约数(greatest common divisor,简写为gcd:或highest common factor,简写为hcf) __gcd(x,y)是algorithm库中的函数 #include<cstdio> #include<algorithm> using namespace std; int n,m; int main() {     scanf("%d %d",&n,&m);     int k=__g…
http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求出一个最小的X,满足X的约数个数为X-K. 对于操作0,分析见这里,搜索需要有力剪枝.对于操作1,代表1至X中不是X的约数个数为K,看似还是搜索,但是由于时限卡的丧心病狂...所以用打表完成 d[i]先用来表示i的约数个数,然后可以模仿素数打表,对于每个数的每个倍数,其d值都自减1,这样就求出每个i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公约数依次为1 2 4 8,那么第 3 个 GCD(X, Y) = 2,也就是从后往前数第3个公共因子. TLE思路:求出 X 的所有因子(从小到大开始存储),再从后往前枚举这些因子,检查是否也为 Y 的因子,统计到第 K 个数就是答案了......以为可以顺利通过,原来数据量还是非常大滴!!! 正确…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more i…
http://acm.hdu.edu.cn/showproblem.php?pid=5019 给出X 和Y,求出第K 大的 X 和Y 的公约数. 暴力求出所有公约数 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector> #inc…
求每个状态里的k优解,然后合并 /* HDU 2639 求01背包的第k大解. 合并两个有序序列 */ #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; ; ][];//dp[i][j]表示容量为i,第j大的值 int value[MAXN]; int weight[MAXN]; ]; ]; int N,V,K; v…
题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[1000005],a2[1000005],x,y,k,g; int cnt1,cnt2,T; LL gcd(LL a,LL b){if(b==0)return a;else return gcd(b,a%b);} int main(){ scanf("%d",&T); while(T--){…
6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的垃圾好多了... HDU 6342(模拟) 贴一下一个队友的代码: //1011-6342-模拟 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include…
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Now given a humble number, please write…