欧拉函数-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}$ . ...
随机推荐
- Java枚举类型的使用,数值的二进制表示
一.Java枚举类型的使用 首先请看这段代码: package java上课; public class EnumTest { public static void main(String[] arg ...
- 阿里云Linux服务器安装Redis 完整步骤(包括处理远程连接问题)
跟随本篇文章步骤,包你成功安装并连接使用. 1.获取redis资源 wget http://download.redis.io/releases/redis-4.0.8.tar.gz 2.解压 tar ...
- Centos7安装gitlab-ce
1.官方推荐方式安装 参考https://www.gitlab.com.cn/installation/#centos-7?version=ce sudo yum install -y curl po ...
- 数据升级包 - bin文件
运行完升级包后,正常的现象 开头: 结尾:
- Hello world-初识C++
刚开始学习编程时,都是以输出Hello world开始的 用C++编写程序输出Hello world如下: #include<iostream>using namespace std;in ...
- 六、JVM之垃圾回收
GC日志 -Xmx1024m -Xms1024m -XX:+PrintGCDetails Heap PSYoungGen total 305664K, used 26214K [0x00000000e ...
- 基于alpine的php-fpm扩展swoole和pdo_mysql
vim Dockerfile 插入一下内容 FROM php:fpm-alpine RUN echo http://mirrors.aliyun.com/alpine/v3.10/main>/e ...
- 关于微信小程序
1.设置了tabBar的页面,好像用navigator跳不过去.
- Oracle允许IP访问配置
http://www.linuxidc.com/Linux/2014-10/108650.htm 1.oracle服务器下/opt/app/oracle/product/11.2.0/network/ ...
- (转)DNS使用的是TCP协议还是UDP协议
转自:DNS使用的是TCP协议还是UDP协议 DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下 ...