POJ2480 Longge's problem gcd&&phi】的更多相关文章

题意简洁明了.做这题主要是温习一下phi的求法.令gcd(i,n)=k,实际上我们只需要求出有多少个i使得gcd(i,n)=k就可以了,然后就转化成了求phi(n/k)的和,但是n很大,我们不可能预处理出所有的phi,但是因为k的个数是O(sqrt(n))级别的,所以我们只需要求出sqrt(n)个数的phi就可以了,我们先预处理出所有的质因子及其个数,然后dfs一下就可以了. #pragma warning(disable:4996) #include<cstring> #include<…
题意 Language:Default Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10642 Accepted: 3563 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some gracefu…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9190   Accepted: 3073 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
题目链接:传送门 题目需求: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. 这题就是上一篇博客的变形. 题目解析:首先先求出与N互质的个数,即N的欧拉函数值,之后分解出N的因子来,求解方法如下. 证明: 要求有多少个 i 满足gcd(i, N) = d 如果gcd(i, N) = d,则gcd(i/d, N/d) = 1 由于i <= N,所以 i/d <= N/d,…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6918   Accepted: 2234 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i,…
Longge's problem 求\(\sum_{i=1}^ngcd(i,n)\),\(n< 2^{31}\). 解 理解1: 注意式子的实际意义,显然答案只可能在n的约数中,而现在问题变成了每个约数出现了几次,而一个约数d要出现的次数,自然需要这个数有约数d,其他的约数与之互斥,于是考虑欧拉函数,故我们有 \[ans=\sum_{d|n}\varphi(n/d)d\] 以此枚举n的约数爆算即可,时间复杂度不难得知为\(O(\sigma(n)\sqrt{n})\). 理解2: 约数计数问题,考…
传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.…
https://leetcode.com/problems/water-and-jug-problem/description/ -- 365 There are two methods to solve this problem : GCD(+ elementary number theory) --> how to get GCF, HCD,  BFS Currently, I sove this by first method 1. how to compute GCD recursive…