LCM Extreme Time Limit: 3000ms Memory Limit: 131072KB   This problem will be judged on UVALive. Original ID: 596464-bit integer IO format: %lld      Java class name: Main Find the result of the following code:unsigned long long allPairLcm(int n){ uns…
题意:给出n [1,3*1e6] 求 并模2^64. 思路:先手写出算式 观察发现可以化成 那么关键在于如何求得i为1~n的lcm(i,n)之和.可以知道lcm(a,b)为ab/gcd(a,b) 变换得(a/gcd) (b/gcd)gcd 由于GCD的性质,可以知道a/gcd 与 b/gcd是互质的两个质数.由此可以想到应用欧拉函数,并且由性质能够证明 nphi(n)/2为小于n所有与n互质数之和(证明:已知一个质数p那么显然n-p与它互质,那么phi(n)中有phi(n)/2对数,每对数和为n…
题面 传送门 题解 拿到式子的第一步就是推倒 \[ \begin{align} \sum_{i=1}^nlcm(n,i) &=\sum_{i=1}^n\frac{in}{\gcd(i,n)}\\ &=n\sum_{i=1}^n\frac{i}{\gcd(n,i)}\\ &=n\sum_{d|n}\sum_{i=1}^n \frac{i}{d}[\gcd(n,i)=d]\\ &=n\sum_{d|n}\sum_{i=1}^{\frac{n}{d}} i[\gcd(i,\fra…
题意:给你一个数N,求N以内和N的最大公约数的和 解题思路: 一开始直接想暴力做,4000000的数据量肯定超时.之后学习了一些新的操作. 题目中所要我们求的是N内gcd之和,设s[n]=s[n-1]+gcd(1,n)+gcd(2,n)+gcd(3,n)+gcd(4,n)....... 再设f[n]=gcd(1,n)+gcd(2,n)+gcd(3,n)+gcd(4,n).......; 思考一下,假设gcd(x,n)=ans,ans便是x和n的最大公约数,那么有几个ans我们将某ans的个数su…
一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the p…
1040 最大公约数之和 题目来源: rihkddd 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题   给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15   Input 1个数N(N <= 10^9) Output 公约数之和 Input示例 6 Output示例 15 /* 51nod 1040 最大公约数之和(欧拉函数) 给你n,然后求[1-n]…
题意:链接 方法:线性欧拉 解析: 首先列一下表达式 gcd(x,y)=z(z是素数而且x,y<=n). 然后我们能够得到什么呢? gcd(x/z,y/z)=1; 最好还是令y>=x 则能够得到我们要的答案就是∑max(y/z)i=1phi(i) 而max(y/z)就是max(n/z). 所以仅仅须要枚举一下质数z随便搞一下就好了,最好用前缀和记录 HINT:前缀和写树状数组的都是(*) 代码: 正常人做法1.1s #include <cstdio> #include <cs…
Problem J GCD Extreme (II) Input: Standard Input Output: Standard Output Given the value of N, you will have to find the value of G. The definition of G is given below:   Here GCD(i,j) means the greatest common divisor of integer i and integer j. For…
1040 最大公约数之和 给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6时,1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 看起来很简单对吧,但是n<=1e9,所以暴力是不行的,所以要把公式进行推导. 引用51nod1040最大公约数之和(欧拉函数) 这个自己上手推一下也很好推的,不过没推过公式的可能不太懂. #include<cstdio> #include<cmath> typedef long long l…
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actu…