仔细看看题目,按照题目要求 其实就是 求 小于等于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. Tinyos学习笔记(一)

    简述:发送和接受数据的程序分别烧录到两个节点上,发送方发送流水灯数据,接受方接受数据并实现流水灯 1.发送和接受程序用到的组件及其接口如图(通过make telosb docs获得)所示:   2.发 ...

  2. About how fast is fast enough for a web application?

    About how fast is fast enough for a web application? Here’s a quick overview of key performance metr ...

  3. [SoapUI] 从上一个测试步骤获取ID list,通过Groovy脚本动态生成 Data Source 供后面的步骤使用

    https://support.smartbear.com/readyapi/docs/testing/data-driven/types/groovy.html 从官网拷贝code到SoapUI里面 ...

  4. sqli-labs:5-6,盲注

    思考1:当# --+都被过滤时,只能考虑闭合处理 思考2:union联合注入时必须先判断字段长度 eg. id=1' order by 3 and '1'='1 sqli5: 首先判断出对id经过了' ...

  5. anaconda的源配置的坑

    anaconda是一个python的科学计算的包集合,它提供了一个非常好用的包管理器 conda,类似于pip. 为了速度(不仅为了速度,没有清华源你就被墙了,速度为0),我们使用清华源: 在类uni ...

  6. vue 获取跳转上一页组件信息

    项目中有一需求,需要根据不同的页面路径url跳转进行不同的操作,首先需要获得上一页面的url,利用 beforeRouteEnter 这个钩子中的from参数获得之前url的信息,然后给 next 传 ...

  7. 【Web】Nginx配置规则

    Nginx配置基本说明 以下是nginx的基本配置文件如下(编辑命令:vi /usr/local/nginx/conf/nginx.conf): #user nobody; #nginx进程数,建议设 ...

  8. 网上流行的linux内核漫画

  9. HDU 6185(打表代码

    /** @xigua */ #include <cstdio> #include <cmath> #include <iostream> #include < ...

  10. 字符串方法 charAt()/charCodeAt()/indexOf()/lastIndexOf()

    charAt()与charCodeAt() 语法:stringObject.charAt(index) 功能:返回stringObject中index位置的字符 语法:stringObject.cha ...