Mophues HDU - 4746 (莫比乌斯反演)
Mophues
\]
题意
求出满足 \(gcd\left(a,b\right) = k\),其中\(1\leq a\leq n,1\leq b \leq m\)且 \(k\) 的因子数 \(\leq P\)
思路
\(g\left(x\right)\) 表示 \(gcd\left(a, b\right) | x\) 的对数
\(f\left(x\right)\) 表示 \(gcd\left(a, b\right) = x\) 的对数
根据莫比乌斯反演有
g\left(n\right) = \sum_{n|d} \mu\left(\frac{d}{n}\right) f\left(d\right) \\
\]
根据题意
\]
那么可以得到
ans &= \sum_{k\in 条件} \sum_{k|d} \mu\left(\frac{d}{k}\right) \lfloor\frac{n}{d}\rfloor\lfloor\frac{m}{d}\rfloor\\
&= \sum_{d}\lfloor\frac{n}{d}\rfloor\lfloor\frac{m}{d}\rfloor \sum_{k|d}\mu\left(\frac{d}{k}\right) \left(k \in 条件\right)
\end{aligned}
\]
因 \(n \leq 10^{5}\),其中最多的因子数不会超过 \(19\)。
令 \(c[d][p]\) 表示 \(\sum_{k|d}\mu\left(\frac{d}{k}\right)\),其中 \(k\) 的因子数\(\leq p\)。通过 \(nlogn\) 暴力打表出 \(p<=19\) 的情况,当 \(p>19\) 时,所有的对数都满足条件。
由于 \(\lfloor\frac{n}{d}\rfloor \lfloor\frac{m}{d}\rfloor\) 的存在,需要整除分块,所以对于求出来的 \(c[d][p]\) 还需要统计前缀和。
/***************************************************************
> File Name : a.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2019年07月17日 星期三 14时38分33秒
***************************************************************/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 5e5 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m, P;
int cas, tol, T;
int pri[maxn], mob[maxn], cnt[maxn];
ll c[maxn][20];
bool ispri[maxn];
void handle() {
mes(pri, 0), mes(ispri, 1);
tol = 0;
int mx = 5e5;
mob[1] = 1;
cnt[1] = 0;
for(int i=2; i<=mx; i++) {
if(ispri[i]) {
pri[++tol] = i;
mob[i] = -1;
cnt[i] = 1;
}
for(int j=1; j<=tol&&i*pri[j]<=mx; j++) {
ispri[i*pri[j]] = false;
cnt[i*pri[j]] = cnt[i]+1;
if(i%pri[j] == 0) {
mob[i*pri[j]] = 0;
break;
} else {
mob[i*pri[j]] = -mob[i];
}
}
}
mes(c, 0);
for(int i=1; i<=mx; i++) {
for(int j=i; j<=mx; j+=i) {
c[j][cnt[i]] += mob[j/i];
}
}
for(int i=1; i<=mx; i++) {
for(int j=1; j<=19; j++) {
c[i][j] += c[i][j-1];
}
}
for(int i=1; i<=mx; i++) {
for(int j=0; j<=19; j++) {
c[i][j] += c[i-1][j];
}
}
}
int main() {
handle();
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &n, &m, &P);
if(n > m) swap(n, m);
if(P > 19) {
printf("%lld\n", 1ll*n*m);
continue;
}
ll ans = 0;
int l = 0, r;
for(int i=1; i<=n; i++) {
r = min(n/(n/i), m/(m/i));
ans += 1ll*(n/i)*(m/i)*(c[r][P]-c[l][P]);
i = r;
l = r;
}
printf("%lld\n", ans);
}
return 0;
}
Mophues HDU - 4746 (莫比乌斯反演)的更多相关文章
- HDU 4746 (莫比乌斯反演) Mophues
这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...
- HDU 4746 莫比乌斯反演+离线查询+树状数组
题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...
- HDU 1695 (莫比乌斯反演) GCD
题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是 ...
- GCD HDU - 1695 莫比乌斯反演入门
题目链接:https://cn.vjudge.net/problem/HDU-1695#author=541607120101 感觉讲的很好的一个博客:https://www.cnblogs.com/ ...
- HDU 5212 莫比乌斯反演
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 1695(莫比乌斯反演)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 6053(莫比乌斯反演)
题意略. 思路:首先想到暴力去扫,这样的复杂度是n * min(ai),对于gcd = p,对答案的贡献应该是 (a1 / p) * (a2 / p) * .... * (an / p),得出这个贡献 ...
- hdu 4746Mophues[莫比乌斯反演]
Mophues Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327670/327670 K (Java/Others) Total ...
- hud 4746 莫比乌斯反演
Mophues Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327670/327670 K (Java/Others)Total S ...
随机推荐
- xshell怎么配置鼠标颜色
在控制面板--> 鼠标属性 --> 指针 --> 文本选择 --> 浏览 --> beam_r.cur --> 打开 --> 应用 --> 确定
- pip install 时报错 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
pip install 时报错: pip is configured with locations that require TLS/SSL, however the ssl module in Py ...
- C库函数strstr分析
C标准库<string.h> 函数声明: char* strstr(char* const _String, char const* const _SubString) 返回值: SubS ...
- Java随堂笔记一
今天开始了Java的正式复习,因为有两三年没有接触Java了,所以打算开始从头复习. 下面使课堂的一些随堂笔记,如果有遗忘,我可以随时翻阅该博客. public static void main(St ...
- ASP.NET Core应用程序容器化、持续集成与Kubernetes集群部署(一)(转载)
本文结构 ASP.NET Core应用程序的构建 ASP.NET Core应用程序容器化所需注意的问题 应用程序的配置信息 端口侦听 ASP.NET Core的容器版本 docker镜像构建上下文(B ...
- SQL Server中临时表是在什么schema下的(转载)
Specifying schema for temporary tables 问: I'm used to seeing temporary tables created with just the ...
- 微信小程序调用云函数出错 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud function service error code -501005, error message Environment not found;
错误异常: Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud ...
- Java 初识
一.Java 简介 1.什么是 Java Java 语言是美国 Sun 公司(Stanford University Network),在1995年推出的高级的编程语言,所谓编程语言,是计算机的语言, ...
- android中fragment卡顿的原因
首页的ViewPager有十几个Fragment,在快速切换的时候,容易产生卡顿现象. 二.分析当ViewPager切换到当前的Fragment时,Fragment会加载布局并显示内容,如果用户这时快 ...
- JAVA自定义查询策略
此文章为个人笔记,考虑之后工作用到,博客方便于查找,如果可以给他人提供参考价值,那再好不过 1.定义查询接口参数 package com.qy.code.generator.query; import ...