HDU-4556-Stern-Brocot Tree
来源:互联网 发布:网络销售期货白银好做 编辑:程序博客网 时间:2024/04/26 02:46
网上有关于这个树的资料,其实它的一半就是法里数列
相关资料:http://zh.wikipedia.org/wiki/%E6%B3%95%E9%87%8C%E6%95%B8%E5%88%97
上面有递推公式,仅仅是需要用较快的方法求出欧拉函数。
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1000011;int n;long long ans[maxn],phi[maxn];void Phi(int n){ phi[1]=1; for(int i=2;i<=n;i++)if(!phi[i]) for(int j=i;j<=n;j+=i) {if(!phi[j]) phi[j]=j;phi[j]=phi[j]/i*(i-1); }}int main(){ Phi(maxn-1); ans[1]=2; ans[2]=3; for(int i=3;i<maxn;i++)ans[i]=ans[i-1]+phi[i]; while(scanf("%d",&n)!=EOF) {long long s=(ans[n]-2)*2+3;printf("%I64d\n",s); } return 0;}
- HDU-4556-Stern-Brocot Tree
- hdu 4556 Stern-Brocot Tree
- hdu 4556 Stern-Brocot Tree
- HDU 4556 Stern-Brocot Tree
- hdu 4556 Stern-Brocot
- HDOJ 4556 Stern-Brocot Tree
- hdu4556-Stern-Brocot Tree
- hdu4556-Stern-Brocot Tree
- Hdu 6209 The Intersection(Stern-Brocot tree+二分)
- hdoj 4556 Stern-Brocot Tree(欧拉函数)
- hdu4556 西山居四 Stern-Brocot Tree
- PE 372 【类欧几里德】【Stern-Brocot Tree】
- HDOJ 题目4556Stern-Brocot Tree(数学,欧拉函数)
- hdoj Stern-Brocot Tree 4556 (欧拉函数打表)
- Farey序列(Stern-Brocot tree的衍生)
- [Codeforces 585C] Alice, Bob, Oranges and Apples (Stern-Brocot Tree + 更相减损法)
- hdu4556 Stern-Brocot Tree(欧拉函数递推关系)
- Farey序列与Stern-Brocot树
- Ubuntu下无法启动Eclipse的原因(版本不兼容)
- java获取路径
- 阿里忙收购,李彦宏在忙…“深度学习
- ORA-12154: TNS错误的处理
- 调用google地图
- HDU-4556-Stern-Brocot Tree
- 自定义IOS的UITextField
- 推荐一些socket工具,TCP、UDP调试、抓包工具
- vc++注册表简单操作实例
- Windows XP硬盘安装Ubuntu 12.04双系统图文详解(准备)
- window.dialogArguments
- mysqldump参数详细说明
- LinkedHashMap和HashMap的比较使用
- C#网络编程日记5