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/ ...
随机推荐
- 背包----Proud merchants
一件物品p,q,v 分别表示物品的价格,钱少于q时就不能买,和物品的价值 n表示物品数量,m表示初始有的钱 问最多能买多少东西 01背包 注意点是,因为有一个q作为限制条件,所以n件物品不是随意选的了 ...
- 【转】仅此一文让你明白ASP.NET MVC原理
原文地址:http://www.cnblogs.com/DotCpp/p/3269043.html ASP.NET MVC由以下两个核心组成部分构成: 一个名为UrlRoutingModule的自定义 ...
- 计蒜客 30999 - Sum - [找规律+线性筛][2018ICPC南京网络预赛J题]
题目链接:https://nanti.jisuanke.com/t/30999 样例输入258 样例输出814 题意: squarefree数是指不含有完全平方数( 1 除外)因子的数, 现在一个数字 ...
- Sorted sets
Redis in Action JOSIAH L. CARLSON MANNING Shelter Island ZSETs offer the ability to store a mapping ...
- ddt ddl dml
data-definition language 数据定义语言 data-manipulation language 数据操纵语言 data type definition 文档类型定义
- 【aws】
云服务器EC2 动态调整云服务器ec2 cpu.内存大小: 在ec2实例上右键,Instance settings--> Change Instance Type 选择一个合适的type 云数据 ...
- 【F12】Console命令,让js调试更简单
Console命令,让js调试更简单 一.显示信息的命令 console.log("normal"); // 用于输出普通信息 console.info("informa ...
- 编码问题:python写入文件
方法一:(推荐) line1 = "我爱中国111" line2 = u"我爱祖国222" with open('1.txt','w',encoding='ut ...
- MySQL 5.7怎么爬出暂时表空间的坑
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/n88Lpo/article/details/78126267 导读 怎样确认暂时表是由哪个用户连接创 ...
- js-jquery-Validate校验【一】
一.导入 js 库 <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.j ...