传送门

这题和p2257一样……不过是n和m相同而已……

所以虽然正解是欧拉函数然而直接改改就行了所以懒得再码一遍了2333

不过这题卡空间,记得mu开short,vis开bool

 //minamoto
#include<cstdio>
#define ll long long
const int N=1e7+;
int p[],n,m;short mu[N];bool vis[N];ll sum[N],ans;
void init(int n){
mu[]=;
for(int i=;i<=n;++i){
if(!vis[i]) mu[i]=-,p[++m]=i;
for(int j=;j<=m&&p[j]*i<=n;++j){
vis[i*p[j]]=;
if(i%p[j]==) break;
mu[i*p[j]]=-mu[i];
}
}
for(int j=;j<=m;++j)
for(int i=;i*p[j]<=n;++i)
sum[i*p[j]]+=mu[i];
for(int i=;i<=n;++i) sum[i]+=sum[i-];
}
int main(){
scanf("%d",&n),init(n);
for(int l=,r;l<=n;l=r+){
r=n/(n/l);
ans+=(sum[r]-sum[l-])*(n/l)*(n/l);
}
printf("%lld\n",ans);
return ;
}

洛谷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 统计n以内gcd为质数的数的个数. 求 \(\sum\limits_p \sum\limits_{i=1}^{n ...

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

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

  4. [洛谷P2568]GCD

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

  5. 洛谷P3935 Calculating (莫比乌斯反演)

    P3935 Calculating 题目描述 若xx分解质因数结果为\(x=p_1^{k_1}p_2^{k_2}\cdots p_n^{k_n},令f(x)=(k_1+1)(k_2+1)\cdots ...

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

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

  7. 洛谷 P2568 GCD

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

  8. 洛谷 P2568 GCD 题解

    原题链接 庆祝一下:数论紫题达成成就! 第一道数论紫题.写个题解庆祝一下吧. 简要题意:求 \[\sum_{i=1}^n \sum_{j=1}^n [gcd(i,j)==p] \] 其中 \(p\) ...

  9. 洛谷P2398 GCD SUM (数学)

    洛谷P2398 GCD SUM 题目描述 for i=1 to n for j=1 to n sum+=gcd(i,j) 给出n求sum. gcd(x,y)表示x,y的最大公约数. 输入输出格式 输入 ...

随机推荐

  1. The threads in the thread pool will process the requests on the connections concurrently.

    https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html Most of the executor implem ...

  2. System.IO.File类和System.IO.FileInfo类

    1.System.IO.File类 ※文件create, copy,move,SetAttributes,open,exists ※由于File.Create方法默认向所有用户授予对新文件的完全读写. ...

  3. PAT天梯赛 L2-026. 小字辈 【BFS】

    题目链接 https://www.patest.cn/contests/gplt/L2-026 思路 用一个二维vector 来保存 每个人的子女 然后用BFS 广搜下去,当目前的状态 是搜完的时候 ...

  4. ImageIO 操作图片

    /** * 读取本地图片到另一个本地文件夹 * @throws IOException */ public void copeImageToOtherFolder() throws IOExcepti ...

  5. platform_set_drvdata和platform_get_drvdata用法【转】

    本文转载自:http://www.cnblogs.com/wangxianzhen/archive/2013/04/09/3009530.html 在用到Linux设备驱动的platform框架时,常 ...

  6. hihocoder #1062 : 最近公共祖先·一(小数据量 map+set模拟+标记检查 *【模板】思路 )

    #1062 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在 ...

  7. 对xml文件的sax解析(增删改查)之一

    crud(增删改查): c:creat r:retrieve u:update d:delete 以下笔记来自于韩顺平老师的讲解. 现在是用java来操作. 第一步:新建java工程.file-new ...

  8. BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4986 题目意思:有 n 个box(从左到右编号依次为1~n),每个box里面有一个随机的钥匙,有可能这 ...

  9. POJ1236 Network of Schools (强连通分量,注意边界)

    A number of schools are connected to a computer network. Agreements have been developed among those ...

  10. 深入攻克c语言--day04

    1.将包含字符数字的字符串分开,使得分开后的字符串前一部分是数字后一部分是字母.例 如“h1ell2o3” ->”123hello” #include<stdio.h> #inclu ...