POJ2478 - Farey Sequence(法雷级数&&欧拉函数)
题目大意
直接看原文吧。。。。
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are
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.
题解
欧拉函数的一个应用~~对于输入n,答案就等于phi[1]+phi[2]+……phi[n]
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#define MAXN 1000005
using namespace std;
int phi[MAXN],prime[MAXN],check[MAXN];
void euler_phi()
{
int cnt=0;
memset(check,false,sizeof(check));
phi[1]=1;
for(int i=2; i<MAXN; i++)
{
if(!check[i])
{
prime[cnt++]=i;
phi[i]=i-1;
}
for(int j=0; j<cnt&&i*prime[j]<MAXN; j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
int main()
{
int n;
euler_phi();
while(cin>>n&&n)
{
long long sum=0;
for(int i=2; i<=n; i++)
sum+=phi[i];
cout<<sum<<endl;
}
return 0;
}
POJ2478 - Farey Sequence(法雷级数&&欧拉函数)的更多相关文章
- 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: ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- Farey Sequence (欧拉函数+前缀和)
题目链接:http://poj.org/problem?id=2478 Description The Farey Sequence Fn for any integer n with n >= ...
- POJ_2478 Farey Sequence 【欧拉函数+简单递推】
一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...
- 洛谷UVA12995 Farey Sequence(欧拉函数,线性筛)
洛谷题目传送门 分数其实就是一个幌子,实际上就是求互质数对的个数(除开一个特例\((1,1)\)).因为保证了\(a<b\),所以我们把要求的东西拆开看,不就是\(\sum_{i=2}^n\ph ...
- Farey Sequence(欧拉函数板子题)
题目链接:http://poj.org/problem?id=2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Farey Sequence(欧拉函数)
题意:给出式子F F中分子分母互质,且分子小于分母 例: F2 = {1/2} F3 = {1/3, 1/2, 2/3} F4 = {1/4, 1/3, 1/2, 2/3, 3/4} F5 = {1/ ...
- UVaLive 7362 Farey (数学,欧拉函数)
题意:给定一个数 n,问你0<= a <=n, 0 <= b <= n,有多少个不同的最简分数. 析:这是一个欧拉函数题,由于当时背不过模板,又不让看书,我就暴力了一下,竟然A ...
随机推荐
- C# 目录与文件管理
文件读写 学习了一点点希望对以后的学习工作有帮助 在应用程序中基本任务是对数据的操作,这就是对数据进行访问和保存挤兑数据的读写,应用程序访问一个文本文件叫做“读”:对文本文件的内容进行修改后保存这些修 ...
- NGUI系列教程六(技能冷却的CD效果)
今天来学习一下,如何利用NGUI做技能冷却的CD效果. 1,首先按之前的教程Create Your UI,Camera为Simple 2D 最终如下图: 2,添加一个按钮,Background 为一张 ...
- mvc3.0中[ValidateInput(false)]失效的问题
在asp.net mvc3.0中[ValidateInput(false)]特性失效了,只需要在网站根目录中的web.config中做如下配置即可: <system.web> <ht ...
- new 的用法
在C#中,new关键字有三种用法: 1.new 运算符,用于创建对象和调用构造函数. 2.new 修饰符,在用作修饰符时,new关键字可以显式隐藏从基类继承的成员. 3.new 约束 ,用于在泛型 ...
- python里面的几个编码函数
时不时的被编码折腾一下 >>> print urllib.quote('中国') %E4%B8%AD%E5%9B%BD >>> s = '%E4%B8%AD%E5% ...
- 随机产生字母a--z, A-Z 的任意组合
VERSION 1.0 引自: http://www.coderanch.com/t/134491/Security/generating-secure-tokens package demo; ...
- Codeforces Round #211 (Div. 2)
难得一次比赛能够自己成功A掉四个题: A题:水题,模拟一下就行: #include <iostream> #include <cstdio> using namespace s ...
- 四大主流云平台对比--CloudStack, Eucalyptus, vCloud Director和OpenStack。
我迟早可能都要进入的领域,提前温习... 还有KVM,ESXI,API,XEN之间的术语和关系,也要心中有数.. ~~~~~~~~~~~~~~~~~~~ 云计算在如今的IT界一直是一个最热门的话题,鉴 ...
- hdu 2089 不要62(初学数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给定 m,.n; 求车牌号 m~n之间 有多少数字 不含 4或62 ,8652是可以的 . ...
- Windows系统中IIS 6.0+Tomcat服务器环境的整合配置过程
IIS6.0+Tomcat整合 1.首先准备工作 Windows IIS 6.0 apache-tomcat-7.0.26.exe tomcat-connectors-1.2.33-windows-i ...