bzoj 2820 YY的GCD(莫比乌斯反演)
Description
Input
Output
Sample Input
10 10
100 100
Sample Output
2791
HINT
T = 10000
N, M <= 10000000
【思路】

唉??click here
【代码】
#include<cstdio>
#include<algorithm>
using namespace std; typedef long long ll;
const int N = 1e7+; ll mu[N],sum[N],su[N],sz,np[N]; void get_mu()
{
int i,j;
mu[]=;
for(i=;i<N;i++) {
if(!np[i]) {
su[++sz]=i;
mu[i]=-;
}
for(j=;j<=sz&&i*su[j]<N;j++) {
np[i*su[j]]=;
if(i%su[j]==) mu[i*su[j]]=;
else mu[i*su[j]]=-mu[i];
}
}
for(i=;i<=sz;i++)
for(j=su[i];j<N;j+=su[i])
sum[j]+=mu[j/su[i]];
for(i=;i<N;i++)
sum[i]+=sum[i-];
}
ll C(int n,int m)
{
int i,last; ll res=;
if(n>m) swap(n,m);
for(i=;i<=n;i=last+) {
last=min(n/(n/i),m/(m/i));
res+=(n/i)*(m/i)*(sum[last]-sum[i-]);
}
return res;
}
int main()
{
get_mu();
int T,n,m;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
printf("%lld\n",C(n,m));
}
return ;
}
bzoj 2820 YY的GCD(莫比乌斯反演)的更多相关文章
- [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块)
[BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块) 题面 给定N, M,求\(1\leq x\leq N, 1\leq y\leq M\)且gcd(x, y)为质数的(x, y)有多少对. ...
- BZOJ 2820: YY的GCD [莫比乌斯反演]【学习笔记】
2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1624 Solved: 853[Submit][Status][Discu ...
- Bzoj 2820: YY的GCD(莫比乌斯反演+除法分块)
2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MB Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x& ...
- bzoj 2820 YY的GCD 莫比乌斯反演
题目大意: 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 这里就抄一下别人的推断过程了 后面这个g(x) 算的方法就是在线性 ...
- bzoj 2820 YY的GCD - 莫比乌斯反演 - 线性筛
Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对kAc这种 傻×必 ...
- BZOJ 2820: YY的GCD 莫比乌斯反演_数学推导_线性筛
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...
- BZOJ 2820 YY的GCD ——莫比乌斯反演
我们可以枚举每一个质数,那么答案就是 $\sum_{p}\sum_{d<=n}\mu(d)*\lfloor n / pd \rfloor *\lfloor m / pd \rfloor$ 直接做 ...
- 【莫比乌斯反演】关于Mobius反演与gcd的一些关系与问题简化(bzoj 2301 Problem b&&bzoj 2820 YY的GCD&&BZOJ 3529 数表)
首先我们来看一道题 BZOJ 2301 Problem b Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd( ...
- 【刷题】BZOJ 2820 YY的GCD
Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对kAc这种傻×必然 ...
- SPOJ PGCD 4491. Primes in GCD Table && BZOJ 2820 YY的GCD (莫比乌斯反演)
4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the results of ...
随机推荐
- mac下设置maven环境
在mac系统下设置maven环境. 1.首先通过终端打开 .bash_profile 2.设置maven解压后的路径地址 环境变量设置如下: MAVEN_HOME .PATH 两个变量即可 3. ...
- (转)基于即时通信和LBS技术的位置感知服务(一):提出问题及解决方案
一.前言.提出问题 公司最近举行2011年度创新设计大赛,快年底了正打算写写2010年以来Android开发的心得与经验,正好同事出了个点子:假如A和B两个人分别在不同的地点,能不能实现这样的功能,让 ...
- ural 1123
找大于等于原数的最小回文数字 代码比较烂........... #include <iostream> #include <cstdio> #include <cstr ...
- Samza文档翻译 : Comparison Introduction
http://samza.incubator.apache.org/learn/documentation/0.7.0/comparisons/introduction.html 这里有一些使得Sam ...
- lib和dll文件的区别和联系
什么是lib文件,lib和dll的关系如何 (2008-04-18 19:44:37) (1)lib是编译时需要的,dll是运行时需要的. 如果要完成源代码的编译,有lib就够了. 如果也使动态 ...
- swift苹果的下一代语言
http://numbbbbb.github.io/the-swift-programming-language-in-chinese/chapter1/01_swift.html 有时间再看,bas ...
- php析构函数
<?php class Page { function __destruct() { echo "__destruct methor invokes<br>"; ...
- matlab 怎么保存plot的图 到指定文件夹
%%使用print函数,第一个参数一定是figure的句柄,第二个参数设置格式,第三个参数是指定文件夹 %代码如下 h=figure; plot(1:10); print(h,'-djpeg','F: ...
- JBoss7 局域网无法访问 解决方法
JBoss7 局域网无法访问 解决方法 在standalone模式,修改/standalone/configuration/standalone.xml.如下 修改或新增一个interface. &l ...
- Vim Gtags插件
01.Gtags func:查看定义处 02.Gtags -r func:查看引用处 03.Gtags -s text:查看未被数据库定义的tags 04.copen:打开quick fix显示窗口 ...