欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description 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 throu…
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见,x与y仅仅有互质的情况下才会发生(0,0)与(x,y)交点不经过其它的点的情况,对于x,y等于N时,能够选择的点均为小于等于N而且与N互质的数,共Euler(N)个,而且不重叠.所以能够得到递推公式aa[i]=aa[i]+2*Euler(N). 代码: #include <iostream> #i…
一.题目 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…
题意:给你一个数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…
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c有公因子1<b<min(r,c),则(c/b, r/b)在线段(0, 0)(c, r)上,则(c, r)不是可见格点.(充分性) 若r与c互质,显然线段上不存在整点,则(c, r)不是可见格点.(必要性) φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值 也就是横坐标增1后纵坐标合…
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则它就会被点(x0, y0) (x0,y0互质,x/x0==y/y0)挡住.能看见的钉子关于线y=x对称.所以,求出x=2至n的所有与x互质的数的个数φ(x)的和(也就是线y=x右下角(因为φ(x)<x)所有能看见的点的个数)乘以2(对角线两旁的看见的点的个数)+3(那几个特殊点)即为所求. 求φ值时…
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…
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; //欧拉函数模板 int Euler(int n) { int num = n; for(int i = 2;i <= n;i++) { if(n % i == 0) { num = num / i * (i-1); } while(n % i == 0) { n /= i; } } return num…
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int phi(int n){ int ans=n; for(int i=2; i*i<=n; i++) if(n%i==0){ ans -= ans / i; while(n%i==0) n /= i; } if(n>1) ans -= ans / n; return ans; } int main(){…
题目大意:求lcm(1,2)+lcm(1,3)+lcm(2,3)+....+lcm(1,n)+....+lcm(n-2,n)+lcm(n-1,n)解法:设sum(n)为sum(lcm(i,j))(1<=i<j<=n)之间最小公倍数的和,f(n)为sum(i*n/gcd(i,n))(1<=i<n)那么sum(n)=sum(n-1)+f(n).可以用线性欧拉筛选+递推来做. 代码: #include <iostream> #include <cstdio>…