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 ...
随机推荐
- hdu 1272
并查集 要判断这个图是连通的 就是只有一个父节点 #include <cstdio> #include <cstring> #define maxn 100005 int f ...
- linq集合内部赋值
linq集合内部赋值 比如将一个列的值,赋值给另一列 有三种方法: 1. e.Result.ToList().ForEach(n => n.IsIntermediarybool = SetIsI ...
- Android GridView、ListView、ScrollView上下拉刷新
实现方法是将显示的内容最外层的ViewGroup做成一个LinearLayout,并扩展它,使其可以上下拖动. 重点是实现View的onTouch方法. 下载:http://files.cnblogs ...
- EL表达式对数组、集合操作
el表达式是通过${key}的方式获取对象中的值.在el表达式中有如下几个隐含的对象,pageScope,requestSope,sessionScope,applicationScope,如果要取$ ...
- AD15高版软件卡不卡,问题解决大讨论
AD高版软件很卡(包括13 14 15版),这是我遇到过的问题,大家都遇到过的问题, 这里我分享一个解决办法:也请给位有什么好的方法也一起分享. 问题1卡:打开AD15软件, 按住鼠标中键 放大 或 ...
- ScrollView can host only one direct child 解决
主要是ScrollView内部只能有一个子元素,即不能并列两个子元素,所以需要把所有的子元素放到一个LinearLayout内部或RelativeLayout等其他布局方式让后再在这个layout外部 ...
- IE Web 开发支持将迁移到 StackOverflow
http://stackoverflow.com/questions/tagged/internet-explorer
- 跨域使用jsonp 获取天气预报
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> ...
- Ant build.xml 批量打渠道包回顾!打第三方jar包总结
配置: eclipse3.9 + ADT22 + sdk 4.0 eclipse带自动混淆的,不过只有在我们手动创建包的时候,才去打签名,去混淆! 开启混淆这样做吧! 必备文件3个: 当然进行ant打 ...
- Area of a Circle
Area of a Circle Description: Complete the function circleArea so that it will return the area of a ...