\(\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}{ 题解 }\)

\[\sum_{p\in prime} \sum_{i=1}^n \sum_{j=1}^n [gcd(i,j)==p]
\]

\[\sum_{p\in prime} \sum_{i=1}^{\lfloor\frac n p \rfloor} \sum_{j=1}^{\lfloor\frac n p \rfloor} [gcd(i,j)==1]
\]

拿\(\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的更多相关文章

  1. 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)

    P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...

  2. 洛谷 P2568 GCD

    https://www.luogu.org/problemnew/show/P2568#sub 最喜欢题面简洁的题目了. 本题为求两个数的gcd是素数,那么我们将x和y拆一下, 假设p为$gcd(x, ...

  3. 洛谷 - P2568 - GCD - 欧拉函数

    https://www.luogu.org/problemnew/show/P2568 统计n以内gcd为质数的数的个数. 求 \(\sum\limits_p \sum\limits_{i=1}^{n ...

  4. Luogu P2568 GCD

    我们首先发现这样肯定是做不了的,所以我们枚举为\(gcd(x,y)=d\)的\(d\) 然后考虑以下的性质: \(gcd(x,y)=1 \Leftrightarrow gcd(px,py)=p(p为素 ...

  5. 洛谷P2568 GCD(线性筛法)

    题目链接:传送门 题目: 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 ...

  6. [洛谷P2568]GCD

    题目大意:给你$n(1\leqslant n\leqslant 10^7)$,求$\displaystyle\sum\limits_{x=1}^n\displaystyle\sum\limits_{y ...

  7. 【洛谷】P2568 GCD

    前言 耻辱,我这个OI界的耻辱! 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对.输入格式  一个整数N输出格式答案输入输出样例  输入  4  ...

  8. 洛谷 P2568 GCD(莫比乌斯反演)

    题意:$\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(i,j)\epsilon prime]$. 对于这类题一般就是枚举gcd,可得: =$\sum_{d\epsilon prim ...

  9. 「Luogu P2568 GCD」

    看到这是一道紫题还是和gcd有关的才点进来(毕竟数论只会gcd). 前置芝士 质数**(又称素数):因数只有1和本身,但是很特殊的1不是一个质数. gcd**:欧几里得算法,又称辗转相除法,可以在约为 ...

随机推荐

  1. Windows 常见进程

    alg.exe描述: alg.exe是Windows系统的一个重要进程,它的功能是用来处理 Internet 连接共享及防火墙,最好不要结束这个进程.taskmgr.exe描述: Windowsxp ...

  2. CreateMutex实现只能打开一个客户端

    #include "stdafx.h" #include <Windows.h> #include <iostream> using namespace s ...

  3. paramiko 堡垒机

    用paramiko写堡垒机 paramiko paramiko模块,基于SSH用于连接远程服务器并执行相关操作. 基本用法 SSHClient 基于用户名密码连接: 基础用法: import para ...

  4. SQL 实现行列互换

    Oracle:不过大多数是采用 oracle 数据库当中的一些便捷函数进行处理,比如 ”pivot”: MySql:目前没有找到更好的方法 题目:数据库中有一张如下所示的表,表名为sales. 年 季 ...

  5. mybatis中in查询

    xml配置 : <select id="selectPostIn" resultType="dasyskjcdtblVo"> SELECT SYS_ ...

  6. android task stack

    http://www.android100.net/html/201402/22/5690.html

  7. iOS UITableView制作类似QQ好友列表视图

                #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDele ...

  8. 除了ROS ,机器人自主定位导航还能怎么做?

    博客转载自:https://www.leiphone.com/news/201609/10QD7yp7JFV9H9Ni.html 雷锋网(公众号:雷锋网)按:本文作者科技剪刀手,思岚科技技术顾问. 随 ...

  9. rvm 安装后的补充工作:source $HOME/.profile

    rvm安装后会在 $HOME/.bash_profile 文件追加一行代码: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source ...

  10. SDKD 2017 Summer Single Training #03

    今天的题目有 6 个. 第一题: CodeForces - 400D  Dima and Bacteria 这个题实际是不难的,难的可能在题意的理解上还有题干有点长,这个题很考察题意上面,知识点很熟悉 ...