POJ2478(欧拉函数)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 15242 | Accepted: 6054 |
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 <cstdio>
using namespace std;
const int MAXN=;
long long euler[MAXN];
void sieve()
{
for(int i=;i<MAXN;i++) euler[i]=i;
for(int i=;i<MAXN;i+=) euler[i]/=;
for(int i=;i<MAXN;i+=)
{
if(euler[i]==i)
{
for(int j=i;j<MAXN;j+=i)
{
euler[j]=euler[j]*(i-)/i;
}
}
}
for(int i=;i<MAXN;i++)
{
euler[i]+=euler[i-];
}
}
int main()
{
sieve();
int n;
while(scanf("%d",&n)!=EOF&&n!=)
{
printf("%lld\n",euler[n]);
}
return ;
}
POJ2478(欧拉函数)的更多相关文章
- poj2478欧拉函数
打表欧拉函数,求2到n的欧拉函数和 #include<map> #include<set> #include<cmath> #include<queue> ...
- POJ2478 Farey Sequence —— 欧拉函数
题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K To ...
- poj2478(欧拉函数)
题目链接:https://vjudge.net/problem/POJ-2478 题意:给定n,输出集合中元素的数量,集合中的元素为最简小于1的分数,分子分母均属于[1,n-1]. 思路:理清题意后就 ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...
- poj2478 Farey Sequence 欧拉函数的应用
仔细看看题目,按照题目要求 其实就是 求 小于等于n的 每一个数的 欧拉函数值 的总和,为什么呢,因为要构成 a/b 然后不能约分 所以 gcd(a,b)==1,所以 分母 b的 欧拉函数值 ...
- POJ2478(SummerTrainingDay04-E 欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16927 Accepted: 6764 D ...
- poj2478——Farey Sequence(欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18507 Accepted: 7429 D ...
- poj-2478 Farey Sequence(dp,欧拉函数)
题目链接: Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14230 Accepted: ...
随机推荐
- css常用知识点——思维导图
如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/21032425741486 有道云笔记图片链接 http://note.youdao.com/ ...
- NO.2 You must restart adb and Eclipse多种情形分析与解决方案
一.问题描述: 运行android程序控制台输出 The connection to adb is down, and a severe error has occured. ...
- QTabWidget和QtabBar的区别
切换标签tab 是QTabBar int QTabWidget::insertTab ( int index, QWidget * page, const QString & label ) ...
- ALS算法 (面试准备)
ALS算法描述: 1.ALS算法用来补全用户评分矩阵.由于用户评分矩阵比较稀疏,将用户评分矩阵进行分解,变成V和U的乘积.通过求得V和U两个小的矩阵来补全用户评分矩阵. 2.ALS算法使用交替最小二乘 ...
- 记升级mysql后的一次故障
一.问题背景 接上级要求,某生产数据库需要实施备份:刚好漏洞扫描报告出来,mysql 版本需要升级到5.7.20,于是就未雨绸缪,先写脚本.脚本在mysql旧版本下完全可用(未升级前,mysql 为5 ...
- SPOJ - VLATTICE
链接 题意:三维平面,找从(0,0,0)看(n,n,n)能看到的点 题解:很明显就是求gcd(i,j,k)==1的(i,j,k)对数,改一下公式即可,记得要算平行坐标轴的三个平面,还有含0的三个坐标 ...
- 【spark】原理
转自:http://www.cnblogs.com/tgzhu/p/5818374.html Apache Spark是一个围绕速度.易用性和复杂分析构建的大数据处理框架,最初在2009年由加州大学伯 ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle
E. Dasha and Puzzle time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- 条款11:记得在operator=中处理自赋值的情况。
本来的版本是这样的: Widget & Widget::operator=(Widget rhs) { delete pb;//这里可能直接将rhs的pb删除了 pb = new (*rhs. ...
- iis不能访问html
在iis中配置好虚拟目录后,打开目录下的一个html文件,发现不是按照预想的输出,查看源代码后发现代码是: <html><head></head><body& ...