POJ 2478 线性递推欧拉函数
题意:
求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 线性递推欧拉函数的更多相关文章
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 3090 && poj 2478(法雷级数,欧拉函数)
http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)
上三角行恰好是[1,n-1]的欧拉函数 http://www.luogu.org/problem/show?pid=2158#sub //#pragma comment(linker, "/ ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- 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 ...
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
- POJ 3090 Visible Lattice Points 欧拉函数
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
随机推荐
- 51nod-1346: 递归
[传送门:51nod-1346] 简要题意: 给出一个式子a[i][j]=a[i-1][j]^a[i][j-1] 给出a[1][i],a[i][1](2<=i<=131172) 有n个询问 ...
- (三)Fegin声明式服务调用
上一篇,讲了SpringClound中的消费者采用Ribbon+Rest来实现,这回我们用组件Feign来实现服务的消费者,Fegin中也是默认集成了Ribbon的;和Eureka结合也能实现负载均衡 ...
- 26.boost文件库
#define _CRT_SECURE_NO_WARNINGS #include <boost/filesystem/operations.hpp> #include <boost/ ...
- requireJS实现原理分析
下面requireJS实现的基本思路 项目地址https://github.com/WangMaoling/require var require = (function(){ //框架版本基本信息 ...
- 问题集锦 ~ PS
#画正圆 按住鼠标左键 + shift (+alt 从中心扩散) #透明背景 选中选区,图层转换为智能对象,栅格化,按 delete #抠图 魔术棒,套索工具 #填充选区颜色 Ctrl+Del #填充 ...
- Install the high performance Nginx web server on Ubuntu
Look out Apache, there's a web server – Nginx (pronounced Engine X) – that means to dismantle you as ...
- Android 自定义View 之利用ViewPager 实现画廊效果(滑动放大缩小)
http://www.2cto.com/kf/201608/542107.html
- Java数据库连接——PreparedStatement的使用
首先了解Statement和PreparedStatement的区别: 由此可见,一般使用PreparedStatement. 操作数据库SU(Course表),其中Course属性有Cno,Cnam ...
- 如何设置ASP.NET站点页面运行超时
全局超时时间 服务器上如果有多个网站,希望统一设置一下超时时间,则需要设置 Machine.config 文件中的 ExecutionTimeout 属性值.Machine.config 文件位于 % ...
- jquery根据接口返回的值来设置asp:CheckBoxList的选中值
接口返回一个json的值,然后通过jquery来选中asp:CheckBoxList相应选中的值 <asp:CheckBoxList runat="server" Repea ...