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 ...
 
随机推荐
- 微信、QQ浏览器X5内核问题汇总
			
一. 资料汇总 1.前端H5调起QQ浏览器的总结:http://km.oa.com/group/22486/articles/show/210189?kmref=search 2.Android We ...
 - 1238. Folding
			
http://acm.timus.ru/problem.aspx?space=1&num=1238 DP+记忆化搜索 思路不难,关键是最优结果的储存问题,为了编写方便,直接用string储存最 ...
 - sftp搭建
			
在Centos 6.6环境使用系统自带的internal-sftp搭建SFTP服务器. 打开命令终端窗口,按以下步骤操作. 0.查看openssh的版本 ssh -V 使用ssh -V 命令来查看op ...
 - Android Studio Tips and Tricks
			
Android Studio Delete Module 1.选中Module右击,选择 Open Module Settings,打开Project Structure 窗空.(或者选中Module ...
 - UIkit框架之uUInavigationController
			
1.继承链:UIviewcontroller:uiresponder:NSObject 2.如果你想使用一些动画转换,可以遵守 UINavigationControllerDelegate 3.创建导 ...
 - 避免每次输入bundler Exec命令
			
bundle在ruby的世界里是个好东西,它可以用来管理应用程序的依赖库.它能自动的下载和安装指定的gem,也可以随时更新指定的gem. rvm则是一个命令行工具,能帮助你轻松的安装,管理多个ruby ...
 - 浅谈C#中的接口和抽象类
			
C#中接口为"其他方面互不相干"的类型提供公共的服务和特征:C#中class只支持但继承,使用接口却支持多继承,例如:C#中System.String是从System空间中的4个i ...
 - B - 搬寝室
			
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
 - bigworld源码分析(2)—— loginApp分析
			
loginApp是整个bigworld进行用户认证的服务,是用户进入游戏的第一步.本篇主要针对loginApp的认证流程,如何和其他服务进行交互,以及loginApp针对多服务负载的不同做法进行分析. ...
 - C语言解决八皇后问题
			
#include <stdio.h> #include <stdlib.h> /* this code is used to cope with the problem of ...