仔细看看题目,按照题目要求 其实就是 求 小于等于n的 每一个数的 欧拉函数值  的总和,为什么呢,因为要构成 a/b 然后不能约分  所以 gcd(a,b)==1,所以  分母 b的 欧拉函数值  就是 以b为分母的 这样的数有几个,分母b的范围 是小于等于n,所以 直接套一个模版就可以了 ,网上找的  说筛选的比较好,下面代码中有一个 注释掉的 模版 貌似 是错的,还不清楚为什么  弄清楚了 重新 注明一下 


#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set> #define ll long long
#define LL __int64
#define eps 1e-8 //const ll INF=9999999999999; #define inf 0xfffffff using namespace std; //vector<pair<int,int> > G;
//typedef pair<int,int> P;
//vector<pair<int,int>> ::iterator iter;
//
//map<ll,int>mp;
//map<ll,int>::iterator p;
//
//vector<int>G[30012]; #define N 1000012 //LL euler[N];
//int p[N][15];
//int num[N];
LL phi[N]; //void init()//这个模版现在不确定对不对,反正题目用不上
//{
// int i,j;
// euler[1]=1;
// for(i=2;i<N;i++)//筛选法得到数的素因子及每个数的欧拉函数值
// {
// if(!euler[i])
// {
// for(j=i;j<N;j+=i)
// {
// if(!euler[j])
// euler[j]=j;
// euler[j]=euler[j]*(i-1)/i;
// p[j][num[j]++]=i;
// }
// }
// euler[i]+=euler[i-1];
// }
//} void init()//筛选法求欧拉函数的模版 直接复制来的
{
memset(phi, 0, sizeof(phi));
phi[1] = 1;
for(int i = 2; i < N; i++) if(!phi[i])
{
for(int j = i; j < N; j+=i)
{
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i-1);
}
}
return ;
} int main(void)
{
init();
int n;
while(scanf("%d",&n),n)
{
LL ans=0;
for(int i=2;i<=n;i++)
ans+=phi[i];
printf("%I64d\n",ans);
}
}

poj2478 Farey Sequence 欧拉函数的应用的更多相关文章

  1. POJ2478 Farey Sequence —— 欧拉函数

    题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K To ...

  2. poj2478 Farey Sequence (欧拉函数)

    Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...

  3. hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数

    hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...

  4. poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)

    http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...

  5. UVA12995 Farey Sequence [欧拉函数,欧拉筛]

    洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...

  6. poj 2478 Farey Sequence 欧拉函数前缀和

    Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K       Description The Farey Sequence Fn for ...

  7. POJ-2478-Farey Sequence(欧拉函数)

    链接: https://vjudge.net/problem/POJ-2478 题意: The Farey Sequence Fn for any integer n with n >= 2 i ...

  8. Poj 2478-Farey Sequence 欧拉函数,素数,线性筛

    Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14291   Accepted: 5647 D ...

  9. POJ2478 - Farey Sequence(法雷级数&&欧拉函数)

    题目大意 直接看原文吧.... The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rat ...

随机推荐

  1. 一个比较有意思的SDN网络技术相关blog/doc

    http://feisky.xyz/sdn/linux/index.html 涵盖了目前主流的网络技术,所有比较有意思的内容全都覆盖了 SDN网络 目录 基本网络 TCP/IP标准模型 DHCP与DN ...

  2. nim博弈

    尼姆博弈 1.问题模型:有三堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 2.解决思路:用(a,b,c)表示某种局势,显证(0,0,0)是第一种奇异 ...

  3. iOS.Debug.Simulator

    1. iOS Simulator Tips & Tricks http://code.tutsplus.com/tutorials/ios-simulator-tips-tricks--mob ...

  4. BZOJ2721或洛谷1445 [Violet]樱花

    BZOJ原题链接 洛谷原题链接 其实推导很简单,只不过我太菜了想不到...又双叒叕去看题解 简单写下推导过程. 原方程:\[\dfrac{1}{x} + \dfrac{1}{y} = \dfrac{1 ...

  5. 立即响应ScrollView上的子视图的手势

    self.myScrollView.delaysContentTouches = YES; self.myScrollView.CanCancelContentTouches=NO; 写了一个继承sc ...

  6. Expressions入门示例

    学习表达式的入门例子,前提是要对委托有一定的了解,泛型明白一些.using System; using System.Linq; using System.Linq.Expressions; usin ...

  7. NC 6系后台调用接口保存单据

    IPFBusiAction ipf = (IPFBusiAction)NCLocator.getInstance().lookup(IPFBusiAction.class); ipf.processA ...

  8. MySQL中的联结表

    使用联结能够实现用一条SELECT语句检索出存储在多个表中的数据.联结是一种机制,用来在一条SELECT语句中关联表,不是物理实体,其在实际的数据库表中并不存在,DBMS会根据需要建立联结,且会在查询 ...

  9. keepalived+nginx+tomcat+redis集群环境部署

    1.所需软件.jar包.配置文件下载:http://pan.baidu.com/s/1dFgntst 2.环境说明: centos6.5  64位 主节点:192.168.40.121 副节点:192 ...

  10. php file_get_contents 使用3法

    <?php //GET function http_get($url, $params){ return file_get_contents($url.'?'.http_build_query( ...