Farey Sequence
Description
F2 = {1/2}
F3 = {1/3, 1/2, 2/3}
F4 = {1/4, 1/3, 1/2, 2/3, 3/4}
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}
You task is to calculate the number of terms in the Farey sequence Fn.
Input
Output
Sample Input
2
3
4
5
0
Sample Output
1
3
5
9
#include<stdio.h>
#include<string.h>
__int64 e[1000005],ans[1000005];
void fun() ///筛法求
{
int i,j;
for(i=2;i<1000005;i++)
if(!e[i])
for(j=i;j<1000005;j+=i)
{
if(!e[j])
e[j]=j;
e[j]=e[j]-e[j]/i;
}
for(i=1;i<1000005;i++)
ans[i]=ans[i-1]+e[i];
}
int main()
{
int n;
fun();
while(~scanf("%d",&n)&&n)
printf("%I64d\n",ans[n]);
}
Farey Sequence的更多相关文章
- 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 ...
- 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/ ...
- UVA12995 Farey Sequence
UVA12995 Farey Sequence 欧拉函数 同仪仗队那题几乎相同,本质都是求欧拉函数的和 #include<cstdio> #define N 1000000 ],i,j,t ...
- Farey Sequence (素筛欧拉函数/水)题解
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]
洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...
- poj2478——Farey Sequence(欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18507 Accepted: 7429 D ...
随机推荐
- mongo
最近一直在用mongodb,有时候会需要用到统计,在网上查了一些资料,最适合用的就是用aggregate,以下介绍一下自己运用的心得.. 别人写过的我就不过多描述了,大家一搜能搜索到N多一样的,我写一 ...
- IDH2.5.1. Pain Points
1. On Redhat 6.2 after uninstalling a cluster, and re-install IDH 2.5.1, you meet a "can not wr ...
- 黑马程序员——OC语言 内存管理
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)计数器 每个对象内部都保存了一个与之相关联的整数,称为引用计数器,当 ...
- Markov Random Fields
We have seen that directed graphical models specify a factorization of the joint distribution over a ...
- 高通CP Crash分析调试
1. 转换tlcore文件 获取 EBICS0.BIN tl2elf --qconly tlcore 2.使用T32 命令把Riva的dump信息从EBICS0文件分离出来 data.load.BIN ...
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
#!/usr/bin/python指定用什么解释器运行脚本以及解释器所在的位置 # -*- coding: utf-8 -*-用来指定文件编码为utf-8的PEP 0263 -- Defining P ...
- Ubuntu 14.04下安装Hadoop2.4.0 (单机模式)
转自 http://www.linuxidc.com/Linux/2015-01/112370.htm 一.在Ubuntu下创建Hadoop组和hadoop用户 增加hadoop用户组,同时在该组里增 ...
- 腾讯优测干货精选|Android双卡双待适配——隐藏在数据库中的那些秘密
腾讯优测是专业的app自动化测试平台,除了提供兼容性测试,远程真机租用等多维度的测试服务,还有优分享-腾讯内部的移动研发测试干货精选~ 许多APP都希望获取用户通讯录联系人,利用通讯录关系链信息来丰富 ...
- 转:Task任务调度实现生产者消费者模式
我们经常会遇到生产者消费者模式,比如前端各种UI操作事件触发后台逻辑等.在这种典型的应用场景中,我们可能会有4个业务处理逻辑(下文以P代表生产者,C代表消费者): 1. FIFO(先进先出) ...
- rtabmap_ros安装---43
摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 一.前言 RTAB-Map (Real-Time Appearance-Based Mappin ...