题目大意

\(t\)(\(t\leq10^4\))组数据,给定\(n,m\)(\(n,m\leq10^6\))求

\[\sum_{x=1}^{n}\sum_{y=1}^{m}[gcd(x,y)=1]
\]

题解

这个人(点这里)讲得很清楚\(\color{white}{\text{shing太强了}}\)

代码
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define maxn 10000010
#define lim (maxn-10)
#define LL long long
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(LL x)
{
if(x==0){putchar('0'),putchar('\n');return;}
int f=0;char ch[20];
if(x<0)putchar('-'),x=-x;
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
return;
}
int t,n,m,p[maxn],no[maxn],mu[maxn],cnt;
LL f[maxn];
int main()
{
no[1]=mu[1]=1;
rep(i,2,lim)
{
if(!no[i])p[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*p[j]<=lim;j++)
{
no[i*p[j]]=1;
if(i%p[j]==0){mu[i*p[j]]=0;break;}
mu[i*p[j]]=-mu[i];
}
}
rep(i,1,cnt)for(int j=p[i];j<=lim;j+=p[i])f[j]+=mu[j/p[i]];
rep(i,1,lim)f[i]+=f[i-1];
t=read();
while(t--)
{
n=read(),m=read();
if(n>m)swap(n,m);LL ans=0;
for(int l=1,r=0;l<=n;l=r+1)r=min(n/(n/l),m/(m/l)),ans+=(LL)(n/l)*(LL)(m/l)*(f[r]-f[l-1]);
write(ans);
}
return 0;
}

并不对劲的bzoj2820:p2257:YY的GCD的更多相关文章

  1. 【BZOJ2820】YY的GCD(莫比乌斯反演)

    [BZOJ2820]YY的GCD(莫比乌斯反演) 题面 讨厌权限题!!!提供洛谷题面 题解 单次询问\(O(n)\)是做过的一模一样的题目 但是现在很显然不行了, 于是继续推 \[ans=\sum_{ ...

  2. 【BZOJ2820】YY的GCD

    [BZOJ2820]YY的GCD Description 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的( ...

  3. 洛谷 P2257 YY的GCD

    洛谷 P2257 YY的GCD \(solution:\) 这道题完全跟[POI2007]ZAP-Queries (莫比乌斯反演+整除分块) 用的一个套路. 我们可以列出答案就是要我们求: \(ans ...

  4. P2257 YY的GCD

    P2257 YY的GCD 题目描述 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 k ...

  5. [Luogu P2257] YY的GCD (莫比乌斯函数)

    题面 传送门:洛咕 Solution 推到自闭,我好菜啊 显然,这题让我们求: \(\large \sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)\in prime]\) 根 ...

  6. 题解 P2257 YY的GCD

    P2257 YY的GCD 解题思路 果然数论的题是真心不好搞. 第一个莫比乌斯反演的题,好好推一下式子吧..(借鉴了blog) 我们要求的答案就是\(Ans=\sum\limits_{i=1}^{n} ...

  7. 【反演复习计划】【bzoj2820】YY的GCD

    这题跟2818一样的,只不过数据水一点,可以用多一个log的办法水过去…… 原题意思是求以下式子:$Ans=\sum\limits_{isprime(p)}\sum\limits_{i=1}^{a}\ ...

  8. 【BZOJ2820】YY的GCD [莫比乌斯反演]

    YY的GCD Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 求1<=x<=N, ...

  9. BZOJ2820:YY的GCD——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2820 Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x& ...

随机推荐

  1. POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~

    Network Time Limit: 1000MS   Memory Limit: 30000K          Special Judge http://poj.org/problem?id=1 ...

  2. HDU 3932 模拟退火

    HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 #include <iostream> #include <cstdio& ...

  3. TJOI2014

    匹配 给出一个\(n(n\leq80)\)个点对\(n\)个点的带权二分图,求所有最大权匹配的交集. 先求出一个最大权匹配,然后枚举每一条匹配中的边,检验删除该边后是否还能形成最大权匹配.如果能则说明 ...

  4. windows环境下SVN服务器限制注释字数

    1.)打开版本库的D:\SVN版本库\otpv3\hooks, 2.)然后新建一个文件pre-commit.bat.(该目录下有模板文件:pre-commit.impl,你要是感兴趣可以详细看看). ...

  5. Euclidean Nim(bzoj 4147)

    Description Euclid和Pythagoras在玩取石子游戏,一开始有n颗石子. Euclid为先手,他们按如下规则轮流操作: ·若为Euclid操作,如果n<p,则他只能新放入p颗 ...

  6. python学习之-- logging模块

    logging模块功能:提供了标准的日志接口,可以通过它存储各种格式的日志.日志5个级别分:debug(),info(),warning(),error(),critical() logging.ba ...

  7. B. Restaurant--cf579B (贪心)

    http://codeforces.com/problemset/problem/597/B 把右节点从小到大排序  在跑一遍就行了 #include <iostream> #includ ...

  8. Ubuntu 16.04安装SQLite Browser操作SQLite数据库

    安装: sudo apt-get install sqlitebrowser 启动:

  9. Nexus搭建Maven私有仓库

    原文:http://blog.csdn.net/rickyit/article/details/54927101 前言 Nexus Repository Manager is a Javaapplic ...

  10. [转]JS 引擎的执行机制

    转: https://www.cnblogs.com/wancheng7/p/8321418.html ------------------------------------------------ ...