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 ...
随机推荐
- Spring boot 使用@Value注入属性
Spring boot 使用@Value注入属性 学习了:http://blog.csdn.net/hry2015/article/details/72353994 如果启动的时候报错: spring ...
- [Angular] Provide Feedback to Progress Events with Angular’s HttpRequest Object
In some cases your application might need to upload large amounts of data, such as files. Obviously ...
- 纯文本中识别URI地址并转换成HTML
问题 有一段纯文本text, 欲将其插入DOM节点div中. text中可能有超链接, 邮件地址等. 假设有, 识别之. 分析 假设仅仅是纯文本, 插入div中, 仅仅要将div.innerText设 ...
- BCB使用线程删除目录中的图片
BCB新建线程DeleteImgThread类.其会默认继承Thread类,然后在Execute函数中编写代码, void __fastcall DeleteImgThread::Execute() ...
- JAVA配置Tomcat
1.下载tomcat,我jdk是1.8的,网上查了一下,说要安装tomcat8及以上的tomcat 尝试点击,弹出, 2.配置环境 3.安装通过cmd安装 4.点击开启服务 5.输入localhost ...
- WPF 基础
关于布局的规则 控件的布局应该由容器来决定,而不是通过自身使用margin之类的东西来控制位置 避免为控件定义明确的尺寸,但应该限定一个可接受的最大及最小尺寸 不要将界面元素设置成与屏幕坐标相关 容器 ...
- NodeJS学习笔记 (3)域名解析-dns(ok)
域名解析:dns.lookup() 比如我们要查询域名 www.qq.com 对应的ip,可以通过 dns.lookup() . var dns = require('dns'); dns.looku ...
- Centos7 安装 opencv
Centos7 安装 opencv CentOS Linux release 7.2.1511 (Core) 1.安装依赖 yum install https://dl.fedorap ...
- Object-C,NSSet,不可变集合
又到晚上了,继续码代码. 正在此时,老爸一个电话"海阔凭鱼跃,天高任鸟飞",老爸不在为老问题烦我了. 自由了,突然感觉压力好大啊. 将来混的太惨,可咋办啊- 第1个例子是,不可变集 ...
- #error 、 #line 和 #pragma 的使用
1. #error 的用法 (1)#error 是一种预编译器指示字,用于生成一个编译错误消息 (2)用法:#error message //注意:message 不需要用双引号包围 (3)#erro ...