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的更多相关文章

  1. UVA12995 Farey Sequence [欧拉函数,欧拉筛]

    洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...

  2. 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)

    洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...

  3. poj2478 Farey Sequence (欧拉函数)

    Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...

  4. POJ 2478 Farey Sequence

     名字是法雷数列其实是欧拉phi函数              Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  5. Farey Sequence

    Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rationa ...

  6. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  7. POJ2478 - Farey Sequence(法雷级数&&欧拉函数)

    题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...

  8. H - Farey Sequence

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...

  9. Farey Sequence (素筛欧拉函数/水)题解

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...

随机推荐

  1. Mybatis批量insert报错的解决办法【the right syntax to use near '' at line...】

    Java中使用Mybatis批量插入数据时Mapper.xml中的sql如下: <insert id="batchSave"> into t_emp(emp_name, ...

  2. hdu4614 Vases and Flowers【线段树】【二分】

    Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...

  3. ZJU-1003 Crashing Balloon dfs,

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题意(难以描述):A,B两个人从1~100选数乘起来比谁的大(不能选重复的或者 ...

  4. MySQL在windows下的noinstall安装

    1.解压mysql zip软件包 2.配置环境变量 3.修改配置文件my_default.ini添加如下: [mysqld] basedir=D:\MySQL\MySQL Server 5.6(mys ...

  5. Docker基本命令与使用 —— Docker镜像与仓库(二)

    一.查看和删除镜像 1.Docker Image 镜像 容器的基石 层叠的只读文件系统 联合加载(union mount) (存储位置 /var/lib/docker) docker info 2.列 ...

  6. java web启动后执行初始化任务

    写一个类继承ApplicationListener,可以直接引用下述代码,然后调用相应的方法. package com.linewell.system; import com.linewell.cac ...

  7. 洛谷P4035 球形空间产生器 [JSOI2008] 高斯消元

    正解:高斯消元 解题报告: 链接! 昂开始看到以为是,高斯消元板子题? 开始很容易想到的是,虽然是多维但是可以类比二维三维列出式子嘛 但是高斯消元是只能处理一元问题的啊,,,辣怎么处理呢 对的这就是这 ...

  8. BPDU报文(RSTP)

    与STP 的BPDU报文格式相同,就是在flags字段报文中间几位得到应用 主要原理:利用flages位中的Proposal与Agreement来进行协商,从而快速从 discarding 转成 fo ...

  9. express 默认模板引擎

    使用express -t ejs microblog创建出来的居然不是ejs项目,而是jade项目.现在的版本已经没有-t这个命令了,改为express -e microblog.运行完之后,根据提示 ...

  10. 【Python】百度贴吧-中国好声音评论爬爬【自练OK-csv提取格式及评论提取空格等问题待改进】

    代码编写思路: 学习知识点: 1.class=a b(a假设是字体-宋体,b是颜色-蓝色:class中可以同时有两个参数a,b(宋体+蓝色),两者用空格隔开即可) 2.拓展1:想要soup到某个元素, ...