POJ
来源:互联网 发布:淘宝链接转化短链接 编辑:程序博客网 时间:2024/05/29 09:12
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.
There are several test cases. Each test case has only one line, which contains a positive integer n (2 <= n <= 10 6). There are no blank lines between cases. A line with a single 0 terminates the input.
For each test case, you should output one line, which contains N(n) ---- the number of terms in the Farey sequence Fn.
23450
1359
/*参考博客http://www.cnblogs.com/linyujun/p/5194170.htmlp为质数1. phi(p)=p-1,因为质数p除了1以外的因数只有p,故1至p的整数只有p与p不互质 2. 如果i mod p=0,那么phi(i*p)=phi(i)*p 3.若i mod p ≠0,那么phi(i*p)=phi(i)*( p-1 ) */#include <iostream>#include <cstring>const int N=1000007;typedef long long LL;LL phi[N];//欧拉打表LL prime[N];bool vis[N];using namespace std;void js()//线性筛法求欧拉{ int cnt=0; memset(vis,true,sizeof(vis)); for(int i=2;i<N;i++) { if(vis[i]) { prime[cnt++]=i; phi[i]=i-1;//If i if prime,phi[i]=i-1; } for(int j=0;j<cnt&&i*prime[j]<N;j++) { LL k=i*prime[j]; vis[k]=false; if(i%prime[j]==0) { phi[k]=phi[i]*prime[j]; break; } else phi[k]=phi[i]*(prime[j]-1); } }}int main(){ int n; js(); for(int i=2;i<=N;i++) phi[i]+=phi[i-1];//打表 while(cin>>n&&n>0) { cout<<phi[n]<<endl; } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 【hdu2298】【三分】Toxophily
- java的类之间的关系:泛化、依赖、关联、实现、聚合、组合
- 表格删除序列号自动排列序号
- Unity中使用代码加载文本、音频、资源打包
- 解决本地环境连不上远程环境
- POJ
- 常见的进程间通信形式
- 单片机在中断函数里定时器是否还计数问题
- C#中的Dispose模式
- Unreal Engine 4 中的 UI 优化技巧
- ICE简单介绍及使用示例
- QT 正则中的文本捕获函数capturedTexts()等
- CodeVs 2102 石子归并 2
- coderforces 846D Monitor
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
灵芝县
灵草排草钓鱼
灵草王
灵葫空间
灵葫空间 穷四
九转灵葫 君已醉
凡女仙葫之灵界
灵狱
藏灵菇的价格
藏灵菇可以减肥吗
藏灵菇减肥吗
藏灵菇酸奶能减肥吗
藏灵菇菌
藏灵菇做酸奶的危害
藏灵菇价格
灵虎爱在线播放
灵虎爱
灵蛇岛
灵蛇爱
海贼谍影 蛇草花露水
灵谷寺
南京灵谷寺
灵谷寺旅游
灵谷寺萤火虫
灵谷寺景区
南京灵谷寺门票
灵谷寺门票
灵谷景区
灵谷
灵谷洞风景区
灵谷洞旅游
灵谷洞
太灵通下载
平和灵通山宾馆
小灵通电话卡
工银灵通卡的缺陷
牡丹灵通卡
平和灵通岩山上住宿
999感冒灵多少钱
感冒灵颗粒多少钱一盒
探灵笔记多少钱