UVA12995 Farey Sequence
欧拉函数
同仪仗队那题几乎相同,本质都是求欧拉函数的和
#include<cstdio>
#define N 1000000
int n,cnt,pri[N+],i,j,t;
long long phi[N+],s[N+];
bool v[N+];
int main(){
for(i=;i<=N;++i){
if(!v[i]) phi[i]=i-,pri[++cnt]=i;
for(j=;j<=cnt;++j){
t=i*pri[j];
if(t>N) break;
v[t]=;
if(i%pri[j]) phi[t]=phi[i]*(pri[j]-);
else{phi[t]=phi[i]*pri[j];break;}
}
}//线性筛欧拉函数板子
for(i=;i<=N;++i) s[i]=s[i-]+phi[i];
while(scanf("%d",&n)){
if(!n) break;
printf("%lld\n",s[n]);
}return ;
}
UVA12995 Farey Sequence的更多相关文章
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]
洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...
- 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)
洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- POJ 2478 Farey Sequence
名字是法雷数列其实是欧拉phi函数 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Farey Sequence
Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rationa ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...
- H - Farey Sequence
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...
- Farey Sequence (素筛欧拉函数/水)题解
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...
随机推荐
- Google Drive 里的文件下载的方法
Google Drive 里并不提供创建直接下载链接的选项,但是可以通过小小的更改链接形式就能把分享的内容保存到本地.例如,一份通过 Google Drive 分享的文件链接形式为: https:// ...
- PHP-FPM子进程过少解决办法
/usr/local/php/var/log/php-fpm.log报一下错误 server reached pm.max_children setting (5), consider raising ...
- HDU-1166敌兵布阵(线段树)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- Java 多线程(六) synchronized关键字详解
多线程的同步机制对资源进行加锁,使得在同一个时间,只有一个线程可以进行操作,同步用以解决多个线程同时访问时可能出现的问题. 同步机制可以使用synchronized关键字实现. 当synchroniz ...
- Oracle HA 之 测试RAC的功能
作用:在oracle数据库instance级别的冗余,其中只要有一个instance可用即可保证可用性,但是不能保准数据级别的错误. 数据库文件需要放置在共享存储上,理论上一个实例对应一个数据库,实例 ...
- JSON.stringify() 格式化 输出log
调试程序的过程中,我们打印一个日志: console.log(object);,其中object是任意的一个json对象. 在控制台就会看到[object object],而看不到具体的内容. 我们可 ...
- LoadRunner-关联相关(解决方法二)
用例为:添加通知,下发给用户. 录制好脚本,replay时脚本未报错,但实际登录网页操作未完成(只添加了通知,未下发给用户). LR自动关联没有内容,手动查看服务器response,在保存时有一个id ...
- 洛谷P3527 MET-Meteors [POI2011] 整体二分
正解:整体二分 解题报告: 传送门! 还有个双倍经验!(明明是一样的题目为什么你们一个紫一个黑啊喂! 这题首先要想到可以二分嘛,然后看到多组询问肯定就整体二分鸭 那就是基本套路啊,发现是区间修改单点查 ...
- tcp3次握手,https加密,ca认证
参考: https://baijiahao.baidu.com/s?id=1570143475599137&wfr=spider&for=pc