P2568 GCD
\(\color{#0066ff}{ 题目描述 }\)
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对.
\(\color{#0066ff}{输入格式}\)
一个整数N
\(\color{#0066ff}{输出格式}\)
答案
\(\color{#0066ff}{输入样例}\)
4
\(\color{#0066ff}{输出样例}\)
4
\(\color{#0066ff}{数据范围与提示}\)
对于样例(2,2),(2,4),(3,3),(4,2)
1<=N<=10^7
\(\color{#0066ff}{ 题解 }\)
\]
\]
拿\(\varphi\) xjb统计一下就行了
#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 1e7 + 10;
int pri[maxn], tot, n;
LL phi[maxn];
bool vis[maxn];
signed main() {
n = in();
phi[1] = 1;
for(int i = 2; i <= n; i++) {
if(!vis[i]) pri[++tot] = i, phi[i] = i - 1;
for(int j = 1; j <= tot && (LL)i * pri[j] <= n; j++) {
vis[i * pri[j]] = true;
if(i % pri[j] == 0) {
phi[i * pri[j]] = phi[i] * pri[j];
break;
}
else phi[i * pri[j]] = phi[i] * (pri[j] - 1);
}
}
for(int i = 2; i <= n; i++) phi[i] += phi[i - 1];
LL ans = 0;
for(int i = tot; i >= 1; i--) {
ans += (phi[n / pri[i]] << 1LL) - 1;
}
printf("%lld\n", ans);
return 0;
}
P2568 GCD的更多相关文章
- 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)
P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...
- 洛谷 P2568 GCD
https://www.luogu.org/problemnew/show/P2568#sub 最喜欢题面简洁的题目了. 本题为求两个数的gcd是素数,那么我们将x和y拆一下, 假设p为$gcd(x, ...
- 洛谷 - P2568 - GCD - 欧拉函数
https://www.luogu.org/problemnew/show/P2568 统计n以内gcd为质数的数的个数. 求 \(\sum\limits_p \sum\limits_{i=1}^{n ...
- Luogu P2568 GCD
我们首先发现这样肯定是做不了的,所以我们枚举为\(gcd(x,y)=d\)的\(d\) 然后考虑以下的性质: \(gcd(x,y)=1 \Leftrightarrow gcd(px,py)=p(p为素 ...
- 洛谷P2568 GCD(线性筛法)
题目链接:传送门 题目: 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 ...
- [洛谷P2568]GCD
题目大意:给你$n(1\leqslant n\leqslant 10^7)$,求$\displaystyle\sum\limits_{x=1}^n\displaystyle\sum\limits_{y ...
- 【洛谷】P2568 GCD
前言 耻辱,我这个OI界的耻辱! 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对.输入格式 一个整数N输出格式答案输入输出样例 输入 4 ...
- 洛谷 P2568 GCD(莫比乌斯反演)
题意:$\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(i,j)\epsilon prime]$. 对于这类题一般就是枚举gcd,可得: =$\sum_{d\epsilon prim ...
- 「Luogu P2568 GCD」
看到这是一道紫题还是和gcd有关的才点进来(毕竟数论只会gcd). 前置芝士 质数**(又称素数):因数只有1和本身,但是很特殊的1不是一个质数. gcd**:欧几里得算法,又称辗转相除法,可以在约为 ...
随机推荐
- arm开发板6410/2440上mjpg-streamer网络视频服务器移植
摄像头移植 一.环境 主机环境 :ubuntu 10.10 目标板 :FS-S5PC100 主机工具链 :gcc-4.4.5 交叉工具链 :arm-unknown-li ...
- 2015.2.27 UltraEdit中显示XML结构
1选择菜单项 "视图"->"显示方式(着色文件类型)"->"XML": 2选择菜单项 "格式"->&q ...
- samba Nginx
1.samba 2.nfs 3.crond 4.nginx ifconfig yum install net-tools -y ifconfig #查看所有已激活的网卡信息 ifconfig eth0 ...
- CSS——常用
1.超链接样式 a:link {color: #FF0000} /* 未访问的链接 */a:visited {color: #00FF00} /* 已访问的链接 */a:hover {color: ...
- eclipse自动生成带参数说明方法注释
自动生成方法的注释格式,例如 /*** @param str* @return * @throws ParseException*/ 快捷键是alt+shift+j,将光标放在方法名上,按快捷键.会 ...
- python中not的用法
python中的not具体表示是什么: 在python中not是逻辑判断词,用于布尔型True和False,not True为False,not False为True,以下是几个常用的not的用法: ...
- linux设置自动获取IP地址
右键单击,选择设置 勾选桥接模式
- 关于android中出现failed to read row 0,column -1错误
该错误出现的原因是Cursor.getColumnIndex()的参数列名不存在或者错误,这时返回值为-1.出现该错误
- linux终端后台运行
nohup command &(然后X退出即可) &也可用来在终端中同时执行几条命令(并行,最后面不要忘记加&) command1 & command2 & c ...
- 列表控件JList的使用
--------------siwuxie095 工程名:TestUI 包名:com.siwuxie095.ui 类名:TestList.jav ...