POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意
直接看原文吧。。。。
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 are
F2 = {1/2}
F3 = {1/3, 1/2, 2/3}
F4 = {1/4, 1/3, 1/2, 2/3, 3/4}
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}
You task is to calculate the number of terms in the Farey sequence Fn.
题解
欧拉函数的一个应用~~对于输入n,答案就等于phi[1]+phi[2]+……phi[n]
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#define MAXN 1000005
using namespace std;
int phi[MAXN],prime[MAXN],check[MAXN];
void euler_phi()
{
int cnt=0;
memset(check,false,sizeof(check));
phi[1]=1;
for(int i=2; i<MAXN; i++)
{
if(!check[i])
{
prime[cnt++]=i;
phi[i]=i-1;
}
for(int j=0; j<cnt&&i*prime[j]<MAXN; j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
int main()
{
int n;
euler_phi();
while(cin>>n&&n)
{
long long sum=0;
for(int i=2; i<=n; i++)
sum+=phi[i];
cout<<sum<<endl;
}
return 0;
}
POJ2478 - Farey Sequence(法雷级数&&欧拉函数)的更多相关文章
- poj2478——Farey Sequence(欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18507 Accepted: 7429 D ...
- poj-2478 Farey Sequence(dp,欧拉函数)
题目链接: Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14230 Accepted: ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- Farey Sequence (欧拉函数+前缀和)
题目链接:http://poj.org/problem?id=2478 Description The Farey Sequence Fn for any integer n with n >= ...
- POJ_2478 Farey Sequence 【欧拉函数+简单递推】
一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...
- 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)
洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...
- Farey Sequence(欧拉函数板子题)
题目链接:http://poj.org/problem?id=2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Farey Sequence(欧拉函数)
题意:给出式子F F中分子分母互质,且分子小于分母 例: F2 = {1/2} F3 = {1/3, 1/2, 2/3} F4 = {1/4, 1/3, 1/2, 2/3, 3/4} F5 = {1/ ...
- UVaLive 7362 Farey (数学,欧拉函数)
题意:给定一个数 n,问你0<= a <=n, 0 <= b <= n,有多少个不同的最简分数. 析:这是一个欧拉函数题,由于当时背不过模板,又不让看书,我就暴力了一下,竟然A ...
随机推荐
- SDC(3)–set_multicycle_path 最关键的一张图
上图意思是,假如使用 –setup option,默认约束的是 latch clock:假如使用 –hold option,默认约束的是 launch clock.箭头表示不同组合下时钟沿的移动方向. ...
- C#中如何按字节数截取字符串?
http://www.cnblogs.com/xuejie/archive/2012/12/14/2818452.html
- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]:谢勤政-11061197,吴润凡-11061185
一,关于结对编程 结对编程的优点: 1)在开发层次,结对编程能提供更好的设计质量和代码质量,两人合作能有更强的解决问题的能力. 2)对开发人员自身来说,结对工作能带来更多的信心,高质量的产出能带来更高 ...
- DB天气app冲刺第五天
今天上了软工的一节课,感觉自己前几天的方向错了,而且基本是在耗时间,因为虽然一直在努力的看书 编代码,但效果不明显.所以今天要好好想一个新的方向重新来过. 明天送上计划.
- 微软Hololens学院教程-Hologram 212-Voice(语音)【微软教程已经更新,本文是老版本】
这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...
- ie6 css sprites重复加载
如果你使用css sprites,那么在ie6下并不能发挥sprites的作用,它还是会每次再重新 加载这个图片,解决方法为为ie6添加下面这条js: <!--[if IE 6]> ...
- Codeforces Round #210
A:简单题: #include<cstdio> using namespace std; int n,k; int main() { scanf("%d%d",& ...
- Python中通过Image的open之后,去show结果打不开bmp图片,无法正常显示图片
在windows的cmd命令行下,使用Python的PIL库打开并显示一个jpg图片: ? 1 2 3 openedImg = Image.open(saveToFile); print " ...
- [Gauss]POJ1830 开关问题
中文题 题意不多说 这题乍一看 就是求个自由未知量个数 相当简单 其实呢 其中要注意的细节还是很多的: 1.光求了自由未知量个数 还不够 ∵求的是可行方案的总数 因此 答案是 2^(自由未知量个数) ...
- [wikioi]线段覆盖
http://wikioi.com/problem/1214/ 这道题也归为贪心了.我也不是很能分辨,但想法确实是:1.有阶段最优化性:2.前一状态和后一状态有关系. 想法:1.排个序是很自然的想法, ...