题意:多组询问,对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d。

T,a,b,d,x,y<=50000

思路:下底函数分块+积性函数前缀和

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 110000
#define M 410000
#define eps 1e-8
#define pi acos(-1)
#define oo 1e9 int mu[N+],s[N+],prime[N+],flag[N+]; ll calc(int n,int m)
{
if(n>m) swap(n,m);
ll ans=;
int i=;
while(i<=n)
{
ll x=n/i;
ll y=m/i;
int t1=n/x;
int t2=m/y;
int pos=min(t1,t2);
ans+=x*y*(s[pos]-s[i-]);
i=pos+;
}
return ans;
} int main()
{
int cas;
scanf("%d",&cas);
mu[]=;
int m=;
for(int i=;i<=N;i++)
{
if(!flag[i])
{
prime[++m]=i;
mu[i]=-;
}
for(int j=;j<=m;j++)
{
int t=prime[j]*i;
if(t>N) break;
flag[t]=;
if(i%prime[j]==)
{
mu[t]=;
break;
}
mu[t]=-mu[i];
}
}
for(int i=;i<=N;i++) s[i]=s[i-]+mu[i];
while(cas--)
{
int a,b,k;
scanf("%d%d%d",&a,&b,&k);
a/=k; b/=k;
ll ans=calc(a,b);
printf("%lld\n",ans);
}
return ;
}

【BZOJ1101】Zap(莫比乌斯反演)的更多相关文章

  1. 【题解】Zap(莫比乌斯反演)

    [题解]Zap(莫比乌斯反演) 裸题... 直接化吧 [P3455 POI2007]ZAP-Queries 所有除法默认向下取整 \[ \Sigma_{i=1}^x\Sigma_{j=1}^y[(i, ...

  2. BZOJ1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2951  Solved: 1293[Submit][Status ...

  3. Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...

  4. 【BZOJ1101】Zap [莫比乌斯反演]

    Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 对于给定的整数a,b和d,有多少正整 ...

  5. 1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...

  6. bzoj 1101 Zap —— 莫比乌斯反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...

  7. BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)

    手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...

  8. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  9. BZOJ 1101 Zap(莫比乌斯反演)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 给定a,b,d,求有多少gcd(x,y)==d(1<=x<=a&& ...

  10. 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)

    先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...

随机推荐

  1. js中替换字符串

    function formatStr(str){ str=str.replace(/\r\n/ig,"<br/>"); return str; } 要注意两点: 要使用 ...

  2. Mybatis学习记录(1)

    1.Mybatis介绍     Mybatis是apache的一个开源项目iBatis,Mybatis是一个优秀的持久层框架,他对jdbc的操作数据库的过程进行封装,使开发者只需要关注sql本身,不需 ...

  3. 从 Objective-C 里的 Alloc 和 AllocWithZone 谈起

    一.问题起源 一切起源于Apple官方文档里面关于单例(Singleton)的示范代码:Creating a Singleton Instance.主要的争议集中在下面这一段: static MyGi ...

  4. c++ sort用法 学习笔记

    c++ sort排序函数,需要加库#include<algorithm>,语法描述:sort(begin,end,cmp),cmp参数可以没有,如果没有默认非降序排序. 首先是升序排序: ...

  5. 896. Monotonic Array

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  6. 解决iPhone滑动不流畅问题

    前段时间在做一个手机端的页面时遇到了iOS上滑动不流畅的问题,后来才发现安卓上没有问题,才意识到这是兼容性问题引起的,所以遇到问题后快速定位到问题根源非常重要.在网上一搜就找到了解决方案.以后遇到类似 ...

  7. DeepFaceLab小白入门(4):提取人脸图片!

    通过上面级片文章,你应该基本知道了换脸的流出,也能换出一个视频来.此时,你可能会产生好多疑问,比如每个环节点点到底是什么意思,那些黑漆漆屏幕输出的又是什么内容,我换脸效果这么差,该如何提升?等等,好奇 ...

  8. GoF23种设计模式之行为型模式之状态模式

    一.概述         定义对象之间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 二.适用性 1.一个对象的行为取决于它的状态,并且它必须在运行时刻 ...

  9. java做http接口

    问题描述 我要对外提供一个http接口给别人调用...但是我不知道用java怎么做这个接口.请大家详细给我讲讲.从开发到如何发布到服务器.谢谢了 解决方案 如果你这个很简单的话,而且数量也很少,建议直 ...

  10. leetcode-18-remove

    283. Move Zeroes 解题思路: 从nums[0]开始,如果是零就和它后面的第一个非零数交换,不是零就下一位.不贴代码了,比较简单. 27. Remove Element 解题思路: 这道 ...