题意:多组询问,对于给定的整数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. The expected type was 'System.Int64' but the actual value was null.”

    System.InvalidOperationException:“An exception occurred while reading a database value for property ...

  2. linux文件或文件夹常见操作

    创建文件夹 mkdir [-p] DirName  在工作目录下,建立一个名为 A 新的子目录 : mkdir A  在工作目录下的 B目录中,建立一个名为 T 的子目录:    若 B 目录不存在, ...

  3. iOS--获取文件目录的方法

    很多文章都有写这个问题,我只是为了记录一下,免得总翻书... 1.Documents 目录: 你应该将所有的应用程序数据文件写入到这个目录下.这个目录用于存储用户数据或其它应该定期备份的信息. 2.L ...

  4. IOS中将颜色转换为image

    - (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f ...

  5. 【转】VxWorks信号量分析

    Wind内核中有二进制信号量.计数信号量和互斥信号量三种类型,为了是运用程序具有可移植性,还提供了POSIX(可移植操作系统接口)信号量 .在VxWorks中,信号量是实现任务同步的主要手段,也是解决 ...

  6. 【思维题 费用流 技巧】bzoj5403: marshland

    主要还是网络流拆点建图一类技巧吧 Description JudgeOnline/upload/201806/1(4).pdf 题目分析 第一眼看到这题时候只会把每个点拆成4个方向:再强制定向连边防止 ...

  7. NOIP2018

    非常糟糕.从未意识到过考场debuff这么严重. 果不其然,高档选手强如txc实力AK:而像我这样的中档选手就是重在考场发挥和自我调整了吧. 究竟要付出多少代价才能领会一个教训 看来要尝试更自闭一点

  8. 【Python学习之五】高级特性1(切片、迭代、列表生成器、生成器、迭代器)

    1.切片 有一个list—>L = [1,2,3,4,5,6,7]或tuple—>T = (1,2,3,4,5,6,7),如果想取得前三个元素,怎么操作? 硬方法,也是低效的方法是:L= ...

  9. LeetCode之螺旋矩阵

    问题 螺旋矩阵 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素. 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ ...

  10. 多线程辅助类之CountDownLatch(三)

    CountDownLatch信号灯是一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.它可以实现多线程的同步互斥功能,和wait和notify方法实现功能类似,具体 ...