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: ...
随机推荐
- jsp——js事件修改属性样式的两种方法(直接赋值、修改属性)、验证表单符合某要求、阻止表单提交、告诉浏览器不要缓存
代码 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncodi ...
- sqoop数据导入到Hdfs 或者hive
用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql http://www.cnblogs.com/xuyou551/p/7999773.html 用sqoop将mysql ...
- Reflection01_获取Class对象
1.java 代码: package reflectionZ; public class TreflectionZ { public static void main(String[] args) t ...
- vmware增加共享文件夹
增加共享文件夹 VMWare提供共享文件夹功能.前提是在虚拟机中安装VMware tools 1. 安装VMware tools 会自动在虚拟机中的/media/VMware Tools/中有个压缩包 ...
- EditText实现输入限制和校验
EditText实现输入限制和校验 一.方法 1)输入限制 1.通过android:digits限制只能输入小写abc android:digits="abc" 2.通过andro ...
- python函数式编程之高阶函数学习
基本概念 函数式编程,是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量.因此,任意一个函数,只要输入确定,输出就确定的这种函数我们称之为纯函数,我们称这种函数没有副作用.而允许使用 ...
- SimpleDateFormat函数语法
SimpleDateFormat函数语法: G 年代标志符 y 年 M 月 d 日 h 时 在上午或下午 (1~12) ...
- angular之 $watch 和$digest 和$apply和$observe的区别
$watch 代表的就是对数据源的监听,当数据源发生变化,就会触发第二个参数的回调函数 $digest 代表触发一个数据源变化的事件 $apply 代表对于$digest的一个封装,他多了一个参数 . ...
- jq为什么能用$操作
jq对dom节点的操作相信大家都很熟悉, $("input").val("value"); 直接用$来获取dom节点的方式也非常便捷方便,那么他是怎么实现的呢? ...
- 常用algorithm及其Python实现
冒泡排序 def bubble_sort(li): for i in range(len(li)-1): # i表示第几趟 for j in range(len(li)-i-1): # j表示图中的箭 ...