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: ...
随机推荐
- scala学习手记28 - Execute Around模式
我们访问资源需要关注对资源的锁定.对资源的申请和释放,还有考虑可能遇到的各种异常.这些事项本身与代码的逻辑操作无关,但我们不能遗漏.也就是说进入方法时获取资源,退出方法时释放资源.这种处理就进入了Ex ...
- Software Engineering at Google
Google的Fergus Henderson在Software Engineering at Google中介绍了Google的软件工程实践. 软件开发 源码仓库 单一源代码仓库,除了核心配置和安全 ...
- 智课雅思词汇---二十六、形容词后缀-ble
智课雅思词汇---二十六.形容词后缀-ble 一.总结 一句话总结: assemble 英 [ə'semb(ə)l] 美 [ə'sɛmbl] vt. 集合,聚集:装配:收集 vi. 集合,聚集 [ ...
- Shell 概述、截取字符操作等
Shell 是用C语言编写的程序,便于用户与Linux内核系统进行交互. Linux的Shell种类众多,常见的有: Bourne Again Shell (/bin/bash) Bourne She ...
- kvm学习篇
云计算:一种资源的使用模式 弹性,按需付费资源降低成本 公有云:亚马逊.阿里云私有云:混合云: 安装: yum install qemu-kvm qemu-kvm-tools virt-manager ...
- 【河南第十届省赛-B】情报传递
题目描述 抗日战争时期,在国共合作的大背景下,中共不断发展壮大,其情报工作也开始由获取警报性.保卫性信息,向获取军政战略性情报转变.各系统情报组织遵循"荫蔽精干,长期埋伏,积蓄力量,以待时机 ...
- [eShopOnContainers 学习系列] - Index - 开篇索引
[资料] 学习资料来源于 eShopOnContainers wiki 以及 微软官方微服务架构指南 [eShopOnContainers 学习系列] - 00 - 开发环境需求 [eShopOnCo ...
- react bootstrap-loader
1.install npm install bootstrap-loader jquery resolve-url-loader 2.webpack.config.js entry: ['bootst ...
- c++ 霍夫变换检测直线
通常这是一幅边缘图像,比如来自 Canny算子.cv:: Houghlines函数的输出是cV::Vec2f向量,每个元素都是一对代表检测到的直线的浮点数(p,0).在下例中我们首先应用 Canny算 ...
- 使用Android Studio自带的NDK编译JNI
/********************************************************************************** * 使用Android Stud ...