POJ2478(SummerTrainingDay04-E 欧拉函数)
Farey Sequence
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16927 | Accepted: 6764 |
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
- //2017-08-04
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const int N = ;
- int phi[N],prime[N],tot;
- long long ans[N];
- bool book[N];
- void getphi()//线性欧拉函数筛
- {
- int i,j;
- phi[]=;
- for(i=;i<=N;i++)//相当于分解质因式的逆过程
- {
- if(!book[i])
- {
- prime[++tot]=i;//筛素数的时候首先会判断i是否是素数。
- phi[i]=i-;//当 i 是素数时 phi[i]=i-1
- }
- for(j=;j<=tot;j++)
- {
- if(i*prime[j]>N) break;
- book[i*prime[j]]=;//确定i*prime[j]不是素数
- if(i%prime[j]==)//接着我们会看prime[j]是否是i的约数
- {
- phi[i*prime[j]]=phi[i]*prime[j];break;
- }
- else phi[i*prime[j]]=phi[i]*(prime[j]-);//其实这里prime[j]-1就是phi[prime[j]],利用了欧拉函数的积性
- }
- }
- }
- int main()
- {
- int n;
- getphi();
- ans[] = ;
- for(int i = ; i < N; i++){
- ans[i] = ans[i-]+phi[i];
- }
- while(scanf("%d", &n) && n){
- printf("%lld\n", ans[n]);
- }
- return ;
- }
POJ2478(SummerTrainingDay04-E 欧拉函数)的更多相关文章
- POJ2478 Farey Sequence —— 欧拉函数
题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K To ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- poj2478 Farey Sequence 欧拉函数的应用
仔细看看题目,按照题目要求 其实就是 求 小于等于n的 每一个数的 欧拉函数值 的总和,为什么呢,因为要构成 a/b 然后不能约分 所以 gcd(a,b)==1,所以 分母 b的 欧拉函数值 ...
- poj2478(欧拉函数)
题目链接:https://vjudge.net/problem/POJ-2478 题意:给定n,输出集合中元素的数量,集合中的元素为最简小于1的分数,分子分母均属于[1,n-1]. 思路:理清题意后就 ...
- POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...
- poj2478——Farey Sequence(欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18507 Accepted: 7429 D ...
- poj2478欧拉函数
打表欧拉函数,求2到n的欧拉函数和 #include<map> #include<set> #include<cmath> #include<queue> ...
- POJ2478(欧拉函数)
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15242 Accepted: 6054 D ...
- poj-2478 Farey Sequence(dp,欧拉函数)
题目链接: Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14230 Accepted: ...
随机推荐
- C#6.0语言规范(六) 转换
转换能够被视为是一个特定类型的表达式.转换可能会导致给定类型的表达式被视为具有不同的类型,或者它可能导致没有类型的表达式获取类型.转换可以是隐式或显式的,这决定了是否需要显式转换.例如,从类型int到 ...
- Mysql数据优化--DBA梳理珍藏篇
1. 优化SQL 1) 通过show status了解各种sql的执行频率 show status like 'Com_%' 了解 Com_select,Com_insert 的 ...
- Linux学习系列之一:在centos 7.5上安装nginx 以及简单配置
说到Linux我们都知道那是相当相当得重要得啊,在计算机这个行业,开发运维都是离不开它得.我作为一个准毕业生,智商可能不太够,只能自己笨鸟先飞,自己操作起来咯.俗话说的好,好记性不如难笔头嘛.而且ng ...
- 关于如何食用Xcode——用mac的小蒟蒻
前言QwQ 对于一只用Mac的小蒟蒻,没有Dev_c++简直太难受了,用在线IDE写代码又没法保存,那么我们怎么办呢? 好在App Store里有这个好东西 所以我们今天来介绍一下 “如何使用Xcod ...
- odoo开发笔记--模型中常用的方法
create方法在数据表中插入一条记录(或新建一个对象的resource)格式:def create(self,cr,uid,vals,context={})参数:vals:待新建记录的字段值,是一个 ...
- Elasticsearch Java Client连接池
按照Elasticsearch API,在Java端使用是ES服务需要创建Java Client,但是每一次连接都实例化一个client,对系统的消耗很大,即使在使用完毕之后将client close ...
- linux下利用dd命令测试磁盘读写速度
在Linux中,dd命令用于读取.转换和输出数据,它可从标准输入或文件中读取数据并输出到指定文件或标准输出中.该命令使用参数如下: 其中”=“后面的为设置的参数 If = <文件名> : ...
- Mac 下安装.NET Core 与 CLI
.NET Foundation:https://github.com/dotnet/home .NET Core:https://github.com/dotnet/coreclr CLI:https ...
- Hadoop2源码分析-序列化篇
1.概述 上一篇我们了解了MapReduce的相关流程,包含MapReduce V2的重构思路,新的设计架构,与MapReduce V1的区别等内容,今天我们在来学习下在Hadoop V2中的序列化的 ...
- Windows x86 下的 静态代码混淆
0x00 前言 静态反汇编之王,毫无疑问就是Ida pro,大大降低了反汇编工作的门槛,尤其是出色的“F5插件”Hex-Rays可以将汇编代码还原成类似于C语言的伪代码,大大提高了可读性.但个人觉得 ...