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. POJ_3368_Frequent values

    Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19998   Accepted: 7180 ...

  2. 多态设计 zen of python poem 显式而非隐式 延迟赋值

    总结 1.python支持延迟赋值,但是给调用者带来了困惑: 2.显式而非隐式,应当显式地指定要初始化的变量 class Card: def __init__(self, rank, suit): s ...

  3. linux UVC and hardware viewer

    至于从哪个版本开始内核支持UVC,官方的话是“Linux 2.6.26 and newer includes the Linux UVC driver natively.” 1.查看摄像头ID: [r ...

  4. ItunesConnect:上传完二进制文件后在构建版本中找不到

    最近经常遇到上传完二进制文件后在构建版本中找不到的情况: 环境:Xcode 8.2 (8C38) 大致有几种原因,可以按照以下步骤排查下. 排查步骤: 1.检查使用的权限,并info.plist文件中 ...

  5. 不移除通知的话,出现的bug

    没销毁的私聊控制器仍然监听到了通知,发送表情

  6. Centos7网桥配置

    CentOS 的网桥虽然配置了很多次,不过总是记不住那几条,还是简单记录下,增加网桥可以通过brctl命令,但是为了简便快捷,直接生成配置文件即可 1.在/etc/sysconfig/network- ...

  7. promise VS future

    Future and Promise are the two separate sides of an asynchronous operation. promise is used by the & ...

  8. mysql 表基本增删查改

    对表的操作是在某个数据库下才能进行的,所以要先选择数据库 "use 数据库名;" 1.创建数据表 1)"create table 表名 (字段1  类型  [约束],  ...

  9. (3.5)mysql基础深入——mysqld_safe脚本功能及流程

    (3.5)mysql基础深入——mysqld_safe脚本功能及流程 目录 1.mysqld_safe过程总结 2.mysql_safe启动的好处 3.mysqld_safe 参数 4.mysqld_ ...

  10. MySQL完全卸载方法

    1.在控制面板里把Mysql正常卸载 2.C:\Documents and Settings\All Users\Application Data\MySQL 这里还有MySQL的文件,必须要删除 注 ...