POJ2478 Farey Sequence
来源:互联网 发布:淘宝找人代付安全吗 编辑:程序博客网 时间:2024/06/04 18:56
欧拉函数
题目传送门
观察一下式子即可发现,
代码:
#include<cstdio>#include<cstring>#include<algorithm>#define MAXN 1000000using namespace std;typedef long long LL;LL n,phi[MAXN+5];//注意答案是会爆int的void Make(){//递推及前缀和 for (int i=1;i<=MAXN;i++) phi[i]=i; for (int i=2;i<=MAXN;i+=2) phi[i]/=2; for (int i=3;i<=MAXN;i+=2)//递推 if (phi[i]==i) for (int j=i;j<=MAXN;j+=i) phi[j]=phi[j]/i*(i-1); for (int i=3;i<=MAXN;i++) phi[i]+=phi[i-1];//前缀和}int main(){ Make(); while (scanf("%lld",&n)&&n) printf("%lld\n",phi[n]); return 0;}
阅读全文
1 0
- POJ2478 Farey Sequence
- poj2478-Farey Sequence
- POJ2478 Farey Sequence
- POJ2478 Farey Sequence
- Farey Sequence(poj2478)
- [Poj2478]Farey Sequence
- poj2478 Farey Sequence
- poj2478 Farey Sequence
- POJ2478 Farey Sequence
- [poj2478] Farey Sequence
- POJ2478 Farey Sequence
- POJ2478 Farey Sequence
- poj2478 Farey Sequence
- POJ2478 Farey Sequence
- POJ2478 Farey Sequence,欧拉函数
- POJ2478 Farey Sequence【快速求欧拉函数】
- Farey Sequence(Poj2478)(快速求欧拉函数)
- poj2478 Farey Sequence (欧拉函数)
- SPOJNQUEEN-Yet Another N-Queen Problem
- ubuntu 下查看caj文件
- 使用pthread-win32工程编译静态库
- VBA 弹框选择文件路径
- 循环语句
- POJ2478 Farey Sequence
- OpenCV学习笔记(32)图像载入、显示、保存、变换灰度图 总结
- 新华三面试总结(二)
- 2017年10月30日提高组T1 数论
- 剑指offer——面试题47:不用加减乘除做加法
- 常用模板1
- PAT考试乙级1010(C语言实现)
- jvm(四):垃圾收集器初探
- 软件测试基础—易用性测试