The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.  (a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a lit…
/* HDU5514 Frogs http://acm.hdu.edu.cn/showproblem.php?pid=5514 容斥原理 * * */ #include <cstdio> #include <cmath> #include <algorithm> //#define test using namespace std; const long long Nmax=1e5; long long n,m,a[Nmax]; long long book[Nmax]…
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知识点:   欧拉函数.http://www.cnblogs.com/shentr/p/5317442.html 题解一: 当M==1时,显然答案为N. 当M!=1.  X是N的因子的倍数是 gcd(X,N)>1 && X<=N 的充要条件.so  先把N素因子分解, N=     …
题目问[1,n]中与n的gcd大于等于m的数的个数. 好难想... 假设x满足条件,那么gcd(x,n)=d>=m,而x/d与n/d一定互质. 又x<=n,所以x/d<=n/d. 于是gcd(x,n)=d的x个数就等于小于n/d且与n/d互质的个数,即phi(n/d). 不同的d对应的x肯定会不重复,因为它们与n的gcd本来就不同.那么就是枚举最大公约数d,累加phi(n/d)就是答案了. #include<cstdio> #include<cstring> us…
GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1567    Accepted Submission(s): 751 Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes writte…
题目链接:传送门 题目需求:Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.(2<=N<=1000000000, 1<=M<=N), 题目解析: 求(X,N),不用想要分解N的因子,分解方法如下,我一开始直接分解for(int i=2;i<=n/2;i++),这样的话如果n==10^9,那么直接超时,因为这点失误直接浪费了一中午 的时间,要这么分解for(in…
GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3559    Accepted Submission(s): 1921 Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes writt…
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),,)=,(,)=. (a,b) can be e…
题意是给出n个m的约数,问[0,m-1]中至少被其中一个约数整除的整数和.(n<=10000,m<=1000000000) 直接容斥的话,是2^n再拖个log的复杂度,加上当前的数大于m时直接跳出了剪枝,或许会小一点. 但是有一个很重要的性质:我们容斥中所有计算过贡献的数,都是m的因数.换言之,我们计算贡献的数的个数是及其有限的,故可以计算出所有因数贡献的系数. 我们给所有因数赋予互不重叠的“贡献”,定义为所有能被其整除但不能被其他大于它的因数整除的数的和.这种贡献是我们用来表示答案的组成的,…
Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1509    Accepted Submission(s): 498 Problem Description  to m−1 and the frogs are numbered from 1 to n. The i-th frog can jump over exactly …