【欧拉函数表】POJ2478-Farey Sequence】的更多相关文章

[题目大意] 求∑φ(i)(1<=i<=N). [思路] 欧拉函数具有如下的重要推论: 当b是素数时 性质①若b|a,有φ(ab)=φ(a)*b: 性质②若b不|a,有φ(ab)=φ(a)*(b-1). 由此可以得出递推求欧拉函数表的方法: 对于当前φ(i),若未被修改过,这说明它是素数,加入素数表. 对于每个i,枚举小于它的所有素数j.利用性质1和性质2求出φ(ij) #include<iostream> #include<cstdio> #include<cs…
首先我们知道,正方形内个是对称的,关于y=x对称,所以只需要算出来一半的人数 然后乘2+1就行了,+1是(1,1)这个点 开始我先想的递推 那么我们对于一半的三角形,一列一列的看,假设已经求好了第I-1列的,那么第I列加上 之后,不会影响前I-1列能看见的人,那么第I列一共加上I个人,设坐标是(I,Y), 我们可以发现如果gcd(I,Y)<>1的时候这个点是看不见的,因为横纵坐标存在约数,也就是 前面有一个整点点和这个点还有原点在同一直线上(三角形相似),那么我们要找第I列I,Y互质的 点,也…
题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1]+f[2]+f[3]+-+f[n] sum[n-1]=f[1]+f[2]+-+f[n-1] sum[n]=sum[n-1]+f[n] 所以我们求出f[n]的值即可 1~n-1与 n 的最大公约数暴力来求肯定超时: 设gcd(x,n)=i 表示 n 和 x 的最大公约数为i,那么gcd( x/i ,…
<训练指南>p.125 设f[n] = gcd(1, n) + gcd(2, n) + …… + gcd(n - 1, n); 则所求答案为S[n] = f[2]+f[3]+……+f[n]; 求出f[n]即可递推求得S[n]:S[n] = S[n - 1] + f[n]; 所有gcd(x, n)的值都是n的约数,按照约数进行分类,令g(n, i)表示满足gcd(x, n) = i && x < n 的正整数x的个数,则f[n] = sum{ i * g(n, i) | n…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15023   Accepted: 5962 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in…
题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17753   Accepted: 7112 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b…
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler(int n) { int ans=n; for(int i=0;i<cnt&&prime[i]<=n;i++) { if(n%prime[i]==0) { ans=ans-ans/prime[i]; while(n%prime[i]==0) n/=prime[i]; } } if(…
题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few areF2 = {1/2}F3 = {1/3, 1/2, 2/3}F4 = {1/4, 1/3…
Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18507   Accepted: 7429 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b)…
题目链接: Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14230   Accepted: 5624 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd…