P2257 莫比乌斯+整除分块
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+;
int vis[maxn];
int mu[maxn];
int prime[maxn];
int tot=;
int sum1[maxn];
int sum2[maxn];
void get_mu()
{
mu[]=; vis[]=;
for(int i=;i<maxn;i++)
{
if(!vis[i]) {mu[i]=-; prime[++tot]=i; }
for(int j=;j<=tot && i*prime[j]<maxn;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==) break;
mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<=tot;i++)
for(int j=prime[i];j<maxn;j+=prime[i])
sum1[j]+=mu[j/prime[i]];
for(int i=;i<=maxn;i++)
sum2[i]=sum2[i-]+sum1[i];
}
int main()
{
get_mu();
int T; cin>>T;
while(T--)
{
int n,m; cin>>n>>m;
ll ans=;
for(int l=,r;l<=min(n,m);l=r+)
{
// r=min(n,m)/(min(n,m)/l); // l-r;
r=min( n/(n/l),m/(m/l));
ans+=1ll*(n/l)*(m/l)*(sum2[r]-sum2[l-]);
}
/*int t=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(vis[__gcd(i,j)]==0) t++;
}
}*/
cout<<ans<<endl;
}
}
P2257 莫比乌斯+整除分块的更多相关文章
- BZOJ2301——莫比乌斯&&整除分块
题目 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 分析 莫比乌斯经典入门题. (我也刚学,就写 ...
- 洛谷 - P2257 - YY的GCD - 莫比乌斯反演 - 整除分块
https://www.luogu.org/problemnew/show/P2257 求 \(n,m\) 中 \(gcd(i,j)==p\) 的数对的个数 求 $\sum\limits_p \sum ...
- 洛谷 P2257 - YY的GCD(莫比乌斯反演+整除分块)
题面传送门 题意: 求满足 \(1 \leq x \leq n\),\(1 \leq y \leq m\),\(\gcd(x,y)\) 为质数的数对 \((x,y)\) 的个数. \(T\) 组询问. ...
- [POI2007]ZAP-Queries (莫比乌斯反演+整除分块)
[POI2007]ZAP-Queries \(solution:\) 唉,数论实在有点烂了,昨天还会的,今天就不会了,周末刚证明的,今天全忘了,还不如早点写好题解. 这题首先我们可以列出来答案就是: ...
- Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...
- 莫比乌斯反演&整除分块学习笔记
整除分块 用于计算$\sum_{i=1}^n f(\lfloor{n/i} \rfloor)*i$之类的函数 整除的话其实很多函数值是一样的,对于每一块一样的商集中处理即可 若一个商的左边界为l,则右 ...
- P2568 莫比乌斯反演+整除分块
#include<bits/stdc++.h> #define LL long long using namespace std; ; bool vis[maxn]; int prime[ ...
- 洛谷 - UVA11424 - GCD - Extreme (I) - 莫比乌斯反演 - 整除分块
https://www.luogu.org/problemnew/show/UVA11424 原本以为是一道四倍经验题来的. 因为输入的n很多导致像之前那样 \(O(n)\) 计算变得非常荒谬. 那么 ...
- [国家集训队] Crash的数字表格 - 莫比乌斯反演,整除分块
考虑到\(lcm(i,j)=\frac{ij}{gcd(i,j)}\) \(\sum_{i=1}^n\sum_{j=1}^m\frac{ij}{gcd(i,j)}\) \(\sum_{d=1}^{n} ...
随机推荐
- 阿里云已买到域名价格统计js代码
var sum = 0; $('.table-hover tr.ng-scope').each(function(){ sum = sum + parseInt($(this).children()[ ...
- 为什么Vuex内数据改变了而组件没有进行更新?
这两天在进行一个首页的制作,结果就碰到了标题上所述的问题了,用了一天的时间在网上查资料.终于找出了问题所在 Vuex的数据写在store里,在组件中需要用到this.$store.commit() 来 ...
- 固定div的位置——不随窗口大小改变为改变位置
百度首页示例: 我给二维码,和下面文本固定位置 这时html代码 <div id="bar_code"> <div class="img_put&quo ...
- 解决spring3升级到spring4后jackjson报错
1.这里说的是基于spring+springmvc+hibernate框架(其实跟持久层框架也没关系) 2.首先是springmvc的配置,处理json数据都会用到的.第5行是spring-4.x的写 ...
- spring Onions and wine
Before and after the cold dew, the air is drier and the "autumn dryness" is vulnerable. Nu ...
- vue-cli title 里面怎动态显示文字
在路由里每个都添加一个meta[{ path:'/login', meta: { title: '登录页面' }, component:'login' }] main.js里面加如下代码: ...
- SharePoint Framework 基于团队的开发(二)
博客地址:http://blog.csdn.net/FoxDave 本篇介绍SPFx项目的一般开发流程.SharePoint Framework基于开源的工具链,也遵循开源技术栈中其他项目的开发流程. ...
- Liunx find/locate/whereis/which 总结
一.locate 命令 是一个文件查找命令,命令所属软件包 mlocate 不同于 find 命令的是,find命令在整块磁盘中搜索:而 locate命令 在数据路库文件中搜索,当天创建的文件第二天才 ...
- 马凯军201771010116《面向对象与程序设计Java》第十七周学习总结
一.理论知识部分 Java 的线程调度采用优先级策略:优先级高的先执行,优先级低的后执行:多线程系统会自动为每个线程分配一个优先级,缺省时,继承其父类的优先级: 任务紧急的线程,其优先级较高: 同优先 ...
- Python 语法1
函数的定义: """ def 函数名(): 函数内容,函数内容, 函数内容,函数内容, """ ////////////////////// ...