题意:

求sigma phi(n)

思路:

线性递推欧拉函数

(维护前缀和)

//By SiriusRen
#include <cstdio>
using namespace std;
#define maxn 1000005
#define int long long
int n,p[maxn+100],s[maxn+100],phi[maxn+100],tot;
void Phi(){
for(int i=2;i<=maxn;i++){
if(!s[i])p[++tot]=i,phi[i]=i-1;
for(int j=1;j<=tot&&i*p[j]<=maxn;j++){
s[i*p[j]]=1,phi[i*p[j]]=(p[j]-1)*phi[i];
if(i%p[j]==0){
phi[i*p[j]]=phi[i]*p[j];
break;
}
}
}
}
signed main(){
Phi();
for(int i=2;i<=maxn;i++)s[i]=s[i-1]+phi[i];
for(;scanf("%lld",&n)&&n;printf("%lld\n",s[n]));
}

POJ 2478 线性递推欧拉函数的更多相关文章

  1. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  2. poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

    http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...

  3. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  4. P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)

    上三角行恰好是[1,n-1]的欧拉函数 http://www.luogu.org/problem/show?pid=2158#sub //#pragma comment(linker, "/ ...

  5. POJ 2407:Relatives(欧拉函数模板)

    Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accept ...

  6. POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 ...

  7. [poj 3090]Visible Lattice Point[欧拉函数]

    找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...

  8. POJ 3090 Visible Lattice Points 欧拉函数

    链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...

  9. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

随机推荐

  1. Maven导入ojdbc14.jar和ojdbc6.jar

    Maven导入ojdbc14.jar和ojdbc6.jar 学习了:http://blog.csdn.net/johon_medison/article/details/51689690 在 ‘运行’ ...

  2. 关于python的hashlib md5的报错处理

    1.报错信息是:TypeError: Unicode-objects must be encoded before hashing 2.报错信息是:TypeError: object supporti ...

  3. hdu4390-Number Sequence(容斥计算)

    题意:给定b数列.计算有多少种数列 a1,a2,...,an 满足条件 a1*a2*...*an=b1*b2*-*bn (ai>1). 解法:处理出b数列中出现的全部质因子的数量记录在map中, ...

  4. JAXB xml与javaBean的转换

    转自:https://blog.csdn.net/lydong_/article/details/79812626 `1. 1.不认识到犯错,然后得到永久的教训. 也不是所谓的教训吧,真正的教训来自于 ...

  5. _itoa进制转换

    #define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> void main() { int ...

  6. Web前端错题模糊题记录

    title: Web前端错题模糊题记录 toc: true date: 2018-09-20 10:04:36 categories: Web tags: HTML CSS JavaScript HT ...

  7. 移动端1px细线问题

    1可以用伪类实现 .con{position: relative;.con:before { content: " "; position: absolute; left: 0; ...

  8. winforms控件

     我们在开发窗体应用时,控件是必不可少的今天我们就来认识一下控件 在认识控件之前还要先来认识一下窗体具体如下: 认识窗体和控件 窗体                                   ...

  9. swift where 的作用

    条件限定: 类型限定: 结构化查询模式. 用于结构体.记录字段.

  10. SpringCloud学习笔记(10)----Spring Cloud Netflix之声明式 REST客户端 -Feign的高级特性

    1. Feign的默认配置 Feign 的默认配置 Spring Cloud Netflix 提供的默认实现类:FeignClientsConfiguration 解码器:Decoder feignD ...