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**:欧几里得算法,又称辗转相除法,可以在约为 ...
随机推荐
- 使用script转储终端命令输出,或者录制并播放session的内容
摘自:http://leohot.blog.163.com/blog/static/1348656022012729113658473/ 注意: 1. 启动script时没有指定文件名,它会自动记录到 ...
- Oracle OCP提纲
ocp提纲 Oracle SQL 基础 ◆ 标准SQL语言介绍◆ Oracle数据库数据组织形式◆ DDL语句创建表及修改表结构◆ Select语句检索和限制表中数据◆ 从多表中检索数据(连接查询)◆ ...
- Http服务端
第一,使用node提供的http模块 var http=require('http'); 第二,创建一个服务器实例 通过http的createServer()方法. var server=http.c ...
- 部署和调优 2.2 squid反向代理
配置反向代理 打开配置文件 vim /etc/squid/squid.conf 修改 http_port 改为 http_port 80 accel vhost vport 在它下面添加一段 cach ...
- linux命令-sudo普通用户拥有root权限
普通用户权限不够 [root@wangshaojun ~]# su - dennywang[dennywang@wangshaojun ~]$ ls /root/ls: 无法打开目录/root/: 权 ...
- 【Android 多媒体应用】使用 VideoView 播放视频
1.MainActivity.java import android.os.Bundle; import android.support.v7.app.AppCompatActivity; impor ...
- hbase.client.RetriesExhaustedException: Can't get the locations hive关联Hbase查询报错
特征1: hbase.client.RetriesExhaustedException: Can't get the locations 特征2: hbase日志报错如下:org.apache.zoo ...
- jstl 判断 null
<c:if test="${not empty object }"> ${object}不为空 </c:if>
- ArcGIS10拓扑规则-面规则(转)
ArcGIS10拓扑规则-面规则 原创 2013年12月27日 10:20:44 标签: ArcGIS 1879 ARCGIS 10 里提供的拓扑规则共32种,下面一一介绍: 首先介绍的对于面图层的拓 ...
- Codeforces 1108E (Array and Segments) 线段树
题意:给你一个长度为n的序列和m组区间操作,每组区间操作可以把区间[l, r]中的数字都-1,请选择一些操作(可以都不选),使得序列的最大值和最小值的差值尽量的大. 思路:容易发现如果最大值和最小值都 ...