欧拉函数-bzoj2818-简单推导
This article is made by Jason-Cow.
Welcome to reprint.
But please post the writer's address.
http://www.cnblogs.com/JasonCow/
/*
ans=
sigma(for each prime<=n)
{
{
simga(for i=1 to n/now prime) phi[i]
}*2 -1
}
*/
#include <cstdio>
int GI(){
int x=,c=getchar(),f=;
while(c<''||c>''){if(c=='-')f=;c=getchar();}
while(c>=''&&c<='')x=x*+c-'',c=getchar();
return f?-x:x;
}
const int maxn=(int)1e7+;
int p[maxn],cnt;bool flag[maxn];long long ans,phi[maxn];
void init(int n){
phi[]=;
for(int i=;i<=n;i++){
if(!flag[i])p[++cnt]=i,phi[i]=i-;
for(int j=;j<=cnt && i*p[j]<=n;j++){
flag[i*p[j]]=;
if(i%p[j]==){phi[i*p[j]]=phi[i]*p[j];break;}
phi[i*p[j]]=phi[i]*(p[j]-);
}
}
for(int i=;i<=n;i++)phi[i]+=phi[i-];
}
int main(){
int n=GI();
init(n);
for(int i=;i<=cnt;i++)ans+=phi[n/p[i]]*-;
printf("%lld\n",ans);
return ;
}
欧拉函数-bzoj2818-简单推导的更多相关文章
- (hdu step 7.2.2)GCD Again(欧拉函数的简单应用——求[1,n)中与n不互质的元素的个数)
题目: GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- LOJ 1370 Bi-shoe and Phi-shoe(欧拉函数的简单应用)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1370 题意:给你n个整数,第i个整数为Xi.定义phi(k)为k的欧拉函数值,设pi为 ...
- GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导
Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const ...
- lightOJ1370 欧拉函数性质
D - (例题)欧拉函数性质 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB ...
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
- BZOJ2818 欧拉函数
题意:求1--n中满足gcd(x,y)的值为质数的数对(x,y)的数目 ( (x,y)和(y,x)算两个 ) sol: 设p[i]是一个质数,那么以下两个命题是等价的: 1.gcd(x,y)=1 2. ...
- Bzoj-2818 Gcd 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...
- BZOJ2818: Gcd 欧拉函数求前缀和
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...
- 【luogu3768】简单的数学题 欧拉函数(欧拉反演)+杜教筛
题目描述 给出 $n$ 和 $p$ ,求 $(\sum\limits_{i=1}^n\sum\limits_{j=1}^nij\gcd(i,j))\mod p$ . $n\le 10^{10}$ . ...
随机推荐
- jQuery---美女相册案例
美女相册案例 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...
- pod has unbound immediate PersistentVolumeClaims : statefulset挂载不上pv的另一种情况
大家都直到当volumeClaimTemplates匹配不上pv时,会出现statefulset挂载不到pv的问题.错误提示如下: error while running "VolumeBi ...
- Windows新建域时 administrator账户密码不符合要求解决办法~!
解决方法 在cmd 命令行中 输入 net user administrator /passwordreq:yes
- Quick Sort(快速排序)
Quick Sort Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a ...
- Flask知识总结
1.-----------------路由设置的2种方式----------------- 查看源码,route方法里,本质是执行app.add_url_rule() 因此可以这么写(主流方式): @ ...
- rp算法 随机化 刷题记录
刷随机化是真的会上瘾quq 洛谷P3973 [TJOI2015]线性代数 看oiwiki上说可以随机化...于是... 就随机在a[i]上选一位取反,然后更新答案,最后输出答案. ...无话可说 代码 ...
- MongoDB geonear和文本命令驱动程序2.0
文本查询,q作为查询字符串: coll.FindAsync<Foo>(Builders<Foo>.Filter.Text(q)); 文本查询需要一个文本索引.要从C#创建代码, ...
- 想要学好Git,应该掌握哪些基础知识?
说到Git,作为程序员的你,在项目开发中一定会使用到或将来也一定会使用到的,但是我相信,很多在使用Git的人,都只是停留一些简单的操作上,比如提交(commit).拉取(pull).推送(push). ...
- Cron表达式及其使用注意事项
Cron表达式简介 Cron表达式全程Crontab表达式,是描述Crontab定时任务执行周期的一种语法格式.而Cron表达式严格上来说有许多特别的版本.如:Linux的.Spring的.Quart ...
- cmd 运行py脚本,提示找不到xx模块
一.在学习Django+接口自动化测试,用Jenkins做定时任务,cmd运行脚本时提示 "找不到xx模块": 1.原因:Pycharm单独运行脚本时没问题,cmd运行找不到模块. ...