POJ 2478 Farey Sequence
2016-05-25 20:13
453 查看
题目分析
这道题最初我本来想找规律,分析了一下发现确实是这样的,就是F(n) = F(n-1) + 小于n且与n互素的数的个数。那么怎样求与n互素的数的个数呢》》很明显,欧拉公式处理一下进行打表,随后再对F数组进行打表,这样就可以得到本次的解了。#include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long LL; const int maxn = 1000005; LL phi[maxn],f[maxn]; void phi_table(LL *phi) { phi[1] = 1; 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); } } int main() { int n; phi_table(phi); f[2] = 1LL; for(int i = 3; i < maxn; i++) f[i] = f[i-1]+phi[i]; while(scanf("%d", &n) != EOF && n) printf("%I64d\n", f ); return 0; }
相关文章推荐
- req.body,req.query
- 【Leetcode】Unique Paths
- 【Leetcode】Unique Paths II
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
- 【MySQL】Error 1264: out of range value for column
- leetcode之longest-consecutive-sequence
- UI控件大全
- myBatis抛出异常Result Maps collection already contains value ...
- [Codeforces297C]Splitting the Uniqueness(构造)
- iOS开发之高级视图—— UITableView(六)表视图刷新
- arduino 资料
- iOS _ UILabel 调整行间距
- SDUT-2169-Sequence(DP)
- find,vim的编程设置,SUID,SGID,SBIT,软.硬链接,重定向
- UILable 设置多种字体颜色
- iOS开发UI篇—核心动画(转场动画和组动画)
- 对AbstractQueuedSychronizer的粗略理解
- Java中String、StringBuffer和StringBuilder的区别和堆栈内存分配
- Helper2416开发板移植minigui3.0.12之二:移植到开发板
- Vue.js-----轻量高效的MVVM框架(九、组件利用Props传递数据)