欧拉函数-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}$ . ...
随机推荐
- Monkey and Banana HDU - 1069 有点像背包,又像最长上升序列
#include<iostream> #include<algorithm> #include<cstring> #include<vector> us ...
- SVM-支持向量机(三)SVM回归与原理
SVM回归 我们之前提到过,SVM算法功能非常强大:不仅支持线性与非线性的分类,也支持线性与非线性回归.它的主要思想是逆转目标:在分类问题中,是要在两个类别中拟合最大可能的街道(间隔),同时限制间隔侵 ...
- 小I选宾馆
小 I 选宾馆 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小 I 去天津玩啦,一路上,他跟他的同学发生了许多有趣的 ...
- 二分-A - Cable master
A - Cable master Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
- js前端模块化的前世今生
前言: <!DOCTYPE html> <html> <head> <title></title> </head> <sc ...
- jQuery---jQuery对象与DOM对象的区别
jQuery对象与DOM对象的区别 1. DOM对象:使用JavaScript中的方法获取页面中的元素返回的对象就是dom对象.2. jQuery对象:jquery对象就是使用jquery的方法获取页 ...
- jQuery---入口函数的写法
入口函数的写法 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&quo ...
- git push出错的解决办法
今天push代码到线上的时候怎么都不行,尝试了很多办法报了好几种错比如: 反正就是各种错,然后其实不管什么错,你全部Git init 一下然后重新配置 git config --global user ...
- 15分钟带你了解前端工程师必知的javascript设计模式(附详细思维导图和源码)
15分钟带你了解前端工程师必知的javascript设计模式(附详细思维导图和源码) 前言 设计模式是一个程序员进阶高级的必备技巧,也是评判一个工程师工作经验和能力的试金石.设计模式是程序员多年工作经 ...
- Ubuntu18.04 一条命令安装caffe问题
由于caffe安装坑很多,而且caffe框架很久不更新了,微调对框架影响不大,所以对与ubuntu18.04在caffe官网提供了一条命令安装,避免很多踩坑痛苦. CPU的一条命令安装: sudo a ...