P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)
上三角行恰好是[1,n-1]的欧拉函数
http://www.luogu.org/problem/show?pid=2158#sub
//#pragma comment(linker, "/STACK:167772160")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
void fre() {
freopen("in.txt","r",stdin);
}
const int inf = 0x3f3f3f3f;
#define eps 1e-8
// const double pi = acos(-1);
const LL mod = 1e9+;
inline int r(){
int x=,f=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int maxn=1e7;
const int N=;
bool vis[maxn];
int phi[maxn];
int prime[maxn];
int tot;
void p_pri(){
// clc(vis,0);
phi[]=;
tot=;
int i,j;
for(i=;i<=N;i++){
if(!vis[i]){
prime[tot++]=i;
phi[i]=i-;
}
for(j=;j<tot;j++){
if(i*prime[j]>N) break;
vis[i*prime[j]]=true;
if(i%prime[j]==){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else{
phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
} int main(){
int n;
LL ans;
ans=;
scanf("%d",&n);
p_pri();
for(int i=;i<n;i++){
ans+=phi[i];
}
cout<<ans*+<<endl;
return ;
}
P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)的更多相关文章
- BZOJ 2190 仪仗队(线性筛欧拉函数)
简化题意可知,实际上题目求得是gcd(i,j)=1(i,j<=n)的数对数目. 线性筛出n大小的欧拉表,求和*2+1即可.需要特判1. # include <cstdio> # in ...
- Luogu P2158 [SDOI2008]仪仗队【数学/欧拉函数】by cellur925
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- The Euler function(线性筛欧拉函数)
/* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体 ...
- [bzoj 2190][SDOI2008]仪仗队(线性筛欧拉函数)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 分析:就是要线性筛出欧拉函数... 直接贴代码了: memset(ans,,sizeof ...
- 素数的线性筛 && 欧拉函数
O(n) 筛选素数 #include<bits/stdc++.h> using namespace std; const int M = 1e6 + 10 ; int mindiv[M] ...
- 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和
只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...
- Bzoj 2186: [Sdoi2008]沙拉公主的困惑 乘法逆元,线性筛,欧拉函数,数论
2186: [Sdoi2008]沙拉公主的困惑 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2560 Solved: 857[Submit][St ...
- poj1248 (线性筛欧拉函数)(原根)
强烈鸣谢wddwjlss 题目大意:给出一个奇素数,求出他的原根的个数,多组数据. 这里先介绍一些基本性质 阶 设\((a,m)=1\),满足\(a^r \equiv 1 \pmod m\)的最小正整 ...
- noip复习——线性筛(欧拉筛)
整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...
随机推荐
- uva 165
回溯 参考了一下别人的解法 1 必须存在 再枚举下一个数字的时候 从当前可取到的最小数字加一枚举到当前可取到的最大数字加一 /********************************* ...
- Side-by-side assembly
Side-by-side technology is a standard for executable files in Windows 98 Second Edition, Windows 200 ...
- PHP获取APP客户端的IP地址的方法
分析php获取客户端ip 用php能获取客户端ip,这个大家都知道,代码如下: /** * 获取客户端ip * @param number $type * @return string */ func ...
- linux 使用kill命令杀死进程的几个办法
常规篇: 首先,用ps查看进程,方法如下: $ ps -ef ……smx 1822 1 0 11:38 ? 00:00:49 gnome-terminalsmx ...
- ANDROID_MARS学习笔记_S01_002View、监听器初步
一.View.监听器介绍 二.在Activity中获取view和设置属性,设置button的监听器 1.activity_main.xml <LinearLayout xmlns:android ...
- Myeclipse 8.5 优化设置
1.1 更改JavaScript文件默认编码 1.2 关闭Myeclipse不需要的启动项 1.3 取消Myeclipse自动更新 1.4 关闭Myeclipse自动验证 1.5 设置Myeclips ...
- CentOS系统内核升级
yum -y update 升级所有包,改变软件设置和系统设置,系统版本内核都升级 yum -y upgrade 升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变
- Django自定义用户认证系统Customizing authentication
扩展已有的用户模型Extending the existing User model 有两种方法来扩展默认的User Model而不用重写自己的模型.如果你不需要改变存储在数据库中的字段,而只是需要改 ...
- 深入理解ob_flush和flush的区别
ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑… 其实, 他们俩的操作对象不同, 有些情况下, flush根本不做什么事情.. ob_* ...
- GPS(1)核心API及3种列出LocationProvider的方法
GPS的常用API Android SDK为GPS提供了很多API,其中LocationManager类是这些API的核心.所有与GPS相关的操作都由LocationManager对象及其派生的对象完 ...