POJ2478 Farey Sequence —— 欧拉函数
题目链接:https://vjudge.net/problem/POJ-2478
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17753 | Accepted: 7112 |
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
Source
题解:
单纯的欧拉函数。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e6+; int euler[MAXN];
void getEuler()
{
memset(euler, , sizeof(euler));
euler[] = ;
for(int i = ; i<MAXN; i++) if(!euler[i]) {
for(int j = i; j<MAXN; j += i)
{
if(!euler[j]) euler[j] = j;
euler[j] = euler[j]/i*(i-);
}
}
} LL f[MAXN];
void init()
{
getEuler();
f[] = ;
for(int i = ; i<MAXN; i++)
f[i] = f[i-] + euler[i];
} int main()
{
int n;
while(scanf("%d", &n)&&n)
printf("%lld\n", f[n]);
}
POJ2478 Farey Sequence —— 欧拉函数的更多相关文章
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- poj2478 Farey Sequence 欧拉函数的应用
仔细看看题目,按照题目要求 其实就是 求 小于等于n的 每一个数的 欧拉函数值 的总和,为什么呢,因为要构成 a/b 然后不能约分 所以 gcd(a,b)==1,所以 分母 b的 欧拉函数值 ...
- hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]
洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...
- poj 2478 Farey Sequence 欧拉函数前缀和
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Description The Farey Sequence Fn for ...
- POJ-2478-Farey Sequence(欧拉函数)
链接: https://vjudge.net/problem/POJ-2478 题意: The Farey Sequence Fn for any integer n with n >= 2 i ...
- Poj 2478-Farey Sequence 欧拉函数,素数,线性筛
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 5647 D ...
- POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...
随机推荐
- 【WEB基础】HTML & CSS 基础入门(7)表格
表格的基本结构 表格是网页上最常见的元素,它除了可以用来展示数据,还常常被用来排版.虽然现在提倡使用DIV+CSS完成页面布局,但表格框架简单明了,对于繁杂的数据,一个简洁的表格能让其展现的极有条理. ...
- luogu P3808 【模板】AC自动机(简单版)
题目背景 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保证正确的基础上只有两组数据,请不要恶意提交. 管理员提示:本题数据内有重复的单词,且重复单词应该计算多次, ...
- Wannafly挑战赛16
E(pbds) 题意: 1<=m,n<=5e5 分析: 首先指向关系形成了一个基环外向树森林 实际上我们可以完全不用真正的去移动每个球,而只需要在计数的时候考虑考虑就行了 对于树上的情况, ...
- Zab算法详解
Zookeeper使用了一种称为Zab(Zookeeper Atomic Broadcast)的协议作为其一致性复制的核心,据其作者说这是一种新发算法,其特点是充分考虑了Yahoo的具体情况:高吞吐量 ...
- ubuntu允许mysql远程连接
ubuntu允许mysql远程连接 第一步: vim /etc/MySQL/my.cnf找到bind-address = 127.0.0.1 注释掉这行,如:#bind-address = 127.0 ...
- Scut游戏服务器免费开源框架--快速开发(1)
Scut快速开发(1) 1 开发环境 需要安装的软件 a) VS2010开发工具(.Net Framework 4.0以上) 2 HelloWorld 2.1 ...
- Windows系统文件详解【大全】
这是网络上转载的一篇文章,找不到原创的出处了--详细的介绍了WINDOWS系统文件的用途,我想各位保存一份以后说不定会有用吧,呵呵..这里按A到Z为大家分好类了,查询的话可以按键盘的Ctrl+F进行搜 ...
- Android——滑动事件冲突解决
android中的事件类型分为按键事件和屏幕触摸事件,Touch事件是屏幕触摸事件的基础事件. android系统中的每个View的子类都具有下面三个与TouchEvent处理密切相关的方法: (1) ...
- React学习之常用概念
看见一篇不错的文章转载,文章源地址:https://blog.csdn.net/zwp438123895/article/details/69374940 一. State和 Props state ...
- (利用DOM)在新打开的页面点击关闭当前浏览器窗口
1.在开发过程中我们前端的用户体验中有时候会要求点击一个按钮,关闭当前浏览器窗口,用HTML DOM就可做到 2.注意:本次写法要求在新窗口中关闭.target="_blank" ...