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: ...
随机推荐
- ubuntu 14.04 建立wifi热点
昨天突然想起来我可以用笔记本搞一个热点这样我的手机就不用上流量了,但是手机死活搜不到建好的信号,目前的解决方案如下: 直接用ubuntu自带的创建wifi网络功能是不好使的,因为android系统不支 ...
- Codeforces Round #447 (Div. 2) C 构造
现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j 然而现在给 ...
- 通过案例说明struts2的工作流程
本文主要是通过一个例子来说明Struts2的一个工作流程. 首先定义一个登录页面login.jsp: [java] view plaincopy <%@ page language=" ...
- 智课雅思词汇---二十三、名词性后缀mony
智课雅思词汇---二十三.名词性后缀mony 一.总结 一句话总结:Latin: action, result of an action or condition; a suffix that for ...
- XamlParseException异常
一般出现System.Windows.Markup.XamlParseException的错误是由1.dll库加载错误,查询一下你程序中引用的dll你是否加载并引用到程序内.2.程序中引用的文件(tx ...
- cassandra框架模型之二——存储机制 CommitLog MemTable SSTable
四.副本存储 Cassandra不像HBase是基于HDFS的分布式存储,它的数据是存在每个节点的本地文件系统中. Cassandra有三种副本配置策略: 1) SimpleStrategy (Rac ...
- QT延时方法
(转自:http://blog.sina.com.cn/s/blog_613cfe940100kacm.html) 1. void sleep(unsigned int msec){ QTime ...
- C# List 排序
(转自:http://www.cnblogs.com/bradwarden/archive/2012/06/19/2554854.html) 第一种:实体类实现IComparable接口,而且必须实现 ...
- 【第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛-L】用来作弊的药水
链接:https://www.nowcoder.com/acm/contest/90/L来源:牛客网 输入x,a,y,b,(1<=x,a,y,b<=10^9)判断x^a是否等于y^b 前面 ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs
A. Dasha and Stairs time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...