POJ 2478 Farey Sequence
来源:互联网 发布:python 爬虫 定时任务 编辑:程序博客网 时间:2024/06/07 14:51
分母为x的既约真分数用欧拉函数算,因为欧拉函数的值为小于n且与n互素的数,然后遍历一遍,打表即可。
//// main.cpp// Richard//// Created by 邵金杰 on 16/8/2.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>using namespace std;typedef long long LL;const int maxn=1000001;LL phi[maxn],f[maxn];void phi_table(){ for(int i=1;i<=maxn;i++) phi[i]=0; for(int i=2;i<=maxn;i++) { if(!phi[i]) { for(int j=i;j<=maxn;j+=i) { if(!phi[j]) phi[j]=j; phi[j]=phi[j]/i*(i-1); } } } for(int i=2;i<=maxn;i++) { f[i]=f[i-1]+phi[i]; }}int main(){ phi_table(); int n; while(cin>>n) { if(n==0) break; cout<<f[n]<<endl; } return 0;}
0 0
- poj 2478 Farey Sequence
- poj 2478 Farey Sequence
- POJ 2478 Farey Sequence
- POJ 2478 Farey Sequence
- poj - 2478 - Farey Sequence
- poj 2478 Farey Sequence
- poj 2478 Farey Sequence
- poj 2478 Farey Sequence
- POJ 2478 Farey Sequence
- poj 2478 Farey Sequence
- POJ - 2478 Farey Sequence
- POJ 2478 Farey Sequence
- poj 2478 Farey Sequence
- POJ 2478 Farey Sequence
- POJ 2478 Farey Sequence
- poj 2478 Farey Sequence
- POJ 2478 Farey Sequence
- POJ 2478 Farey Sequence
- [THE_PLAN]八月份的第一抹阳光
- K9F1208U0B、K9F2G08X0A NAND FLASH内部的物理结构
- python学习(二):并行开发(线程和进程)
- corners设置多个属性
- zookeeper详解(一) -- 基本结构
- POJ 2478 Farey Sequence
- Eclipse恢复已删除的文件和代码、svn使用了还原,但本地的没有提交找回没提交代码的方法
- linux sed命令详解
- Oracle使用sqlplus和rman无法使用退格、上翻键乱码等问题的解决办法
- Linux C线程的创建和使用
- iOSAutoLayout(自己参考别的理解)
- Maven使用Jetty部署应用
- 【《代码整洁之道》精读与演绎】之一 让代码比你来时更干净
- 自定义直方图平滑函数cvSmoothHist