POJ 2478 Farey Sequence
名字是法雷数列其实是欧拉phi函数
Farey Sequence
Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are
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 There are several test cases. Each test case has only one line, which contains a positive integer n (2 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input.
Output For each test case, you should output one line, which contains N(n) ---- the number of terms in the Farey sequence Fn.
Sample Input 2 Sample Output 1 Source POJ Contest,Author:Mathematica@ZSU
|
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; typedef unsigned long long int LL; LL sum[],phi[]; void phi_table()
{
phi[]=;
for(int i=;i<=;i++)if(!phi[i])
{
for(int j=i;j<=;j+=i)
{
if(!phi[j]) phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
sum[]=;
for(int i=;i<=;i++)
{
sum[i]=sum[i-]+phi[i];
}
} int main()
{
phi_table();
int n;
while(scanf("%d",&n)!=EOF&&n)
{
printf("%llu\n",sum[n]);
}
return ;
}
POJ 2478 Farey Sequence的更多相关文章
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2478 Farey Sequence 欧拉函数前缀和
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Description The Farey Sequence Fn for ...
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...
- 欧拉函数 & 【POJ】2478 Farey Sequence & 【HDU】2824 The Euler function
http://poj.org/problem?id=2478 http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数模板裸题,有两种方法求出所有的欧拉函 ...
- Farey Sequence(欧拉函数板子题)
题目链接:http://poj.org/problem?id=2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Farey Sequence (欧拉函数+前缀和)
题目链接:http://poj.org/problem?id=2478 Description The Farey Sequence Fn for any integer n with n >= ...
- POJ - 2478
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12802 Accepted: 4998 D ...
- POJ2478 Farey Sequence
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15023 Accepted: 5962 Description The ...
随机推荐
- FineReport实现根据点击次数奇偶性排序的方法
使用FineReport报表软在进行排序的时,很多时候您可能想实现根据点击的次数进行升降序排序,也就是说点击第一次点击标题升序排序,再次点击就降序,以此类推,而不是通过选择升序进行升序排列,选择降序进 ...
- 一个开关电源传导、辐射处理案例-----Layout环路
这是一款输入宽电压120-277V 60HZ,输出48V,273mA的电源,使用美芯晟MT7933,采用Buck拓扑结构. 注:在最初的设计中,预留电感L1.L2,CBB电容C1.C2作为传导测试元 ...
- 【2016-11-3】【坚持学习】【Day18】【Oracle 数据类型 与C#映射关系】
大部分类型的对应关系:原文:http://2143892.blog.51cto.com/2133892/499353 序号 Oracle数据类型 .NET类型 GetOracleValue类型 DbT ...
- Android UI控件----ExpandableListView的基本用法
ExpandableListView介绍 ExpandableListView的引入 ExpandableListView可以显示一个视图垂直滚动显示两级列表中的条目,这不同于列表视图(ListVie ...
- NOIP2010pj三国游戏[博弈论]
题目描述 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏. 在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不小于 4),任意两个武将之 ...
- linux-windows资源共享
先安装samba,然后 sudo mount -t cifs //192.168.1.111/Jack_Win_Share /media/ -o username=Jack,password=1,io ...
- eclipse的几个快捷键
Alt / 自动补全 Ctrl Shift F 整理代码 Ctrl / 注释或取消注释 Ctrl 鼠标移到变量或类名上 转到声明/实现的接口/返回类型等 Ctrl Shift O import所有缺失 ...
- 利用DotSpatial发布WMS, WFS服务
我们遇到的几个给政府部门做的GIS系统,一般都只要面子,只要好看,领导高兴得不得了,点点这里点点那里,哟,这按钮一点还会转,领导开心得跟朵花似的...要是搞个各种分析什么的全堆上来,他就嫌烦了...这 ...
- Matlab
Q:workspace没有显示变量的值 A:这是因为子程序里的变量是局部变量,他们的作用域就是子函数内部,会在流程控制回到主调函数前被系统自动释放掉,所以,一旦子程序运行完,你是不可能再查看子程序里的 ...
- Mongodb学习笔记四(Mongodb聚合函数)
第四章 Mongodb聚合函数 插入 测试数据 ;j<;j++){ for(var i=1;i<3;i++){ var person={ Name:"jack"+i, ...