SCP-bzoj-3309
####
**项目编号:bzoj-3309**
项目等级:Safe
项目描述:
特殊收容措施:
以下用$(x, y)$表示$gcd(x, y)$。
$$ |
又有$\epsilon = \mu * 1$,故
$$ |
设$T = d g$,则
$$ |
设$g(T) = \sum _ {d | T} f(d) \mu(\frac T d) = \sum _ {d | T} f(\frac T d) \mu(d)$。
可证明$h(T) = \lfloor {\frac a T} \rfloor \lfloor {\frac b T} \rfloor$的取值只有$\sqrt[]{min(a,b)}$段。
这样对于$h(T)$取值相同的$T$,其总贡献为$h(T) \sum g(T)$,于是只需要线性筛出$g$函数计算前缀和即可。
以下考虑$g(T)$的性质。
因为当且仅当$p ^ 2 \not| d$即$\mu(d) \not= 0$时,$f(\frac T d)$对$g(T)$有贡献。
设$T = \prod _ ^ p _ i ^ , r = max {q _ i}$,
集合$A = {q _ i = r}, B = \complement _ ^ $。
若${\exists}i < j$使得$q _ i \not= q _ j$时:
一旦确定了$A$中d的质因数选取方案,$f(\frac T d)$也随即确定。
此时所有集合$B$中d的质因数选取方案$\sum \mu(d)=0$,故此情况对$g(T)$贡献为0。
$\forall i, j$使得$q _ i = q _ j$时:
当且仅当$d = \prod _ ^ p _ i$时,\(f(d) = r\),否则$f(d) = r - 1$。
故$g(T) = (r \sum \mu(d)) + (-1) ^ {k + 1}$。
又$\sum \mu(d)=0$,故$g(T) = (-1) ^ {k + 1}$。
由此,可根据以上性质筛出g。
附录:
#include <bits/stdc++.h>
#define range(i,c,o) for(register int i=(c);i<(o);++i)
using namespace std;
// QUICK_IO BEGIN HERE
#ifdef __WIN32
#define getC getchar
#define putLL(x,c) printf("%I64d%c",x,c)
#else
#define getC getchar_unlocked
#define putLL(x,c) printf("%lld%c",x,c)
#endif
inline unsigned getU()
{
char c; unsigned r=0;
while(!isdigit(c=getC()));
for(;isdigit(c);c=getC())
{
r=(r<<3)+(r<<1)+c-'0';
}
return r;
}
// QUICK_IO END HERE
static const int MAXN=10000000;
bool flag[MAXN+5]; int pr[MAXN>>2];
int las[MAXN+5]; // for x=y*cur_p^cur_q, las[x]=y
int cnt[MAXN+5]; // for x=y*cur_p^cur_q, cnt[x]=cur_q
int g[MAXN+5]; // g(x)=sigma(f(d)*mu(x/d),d|x)
inline long long solve(const int&x,const int&y)
{
long long ret=0;
for(int i=1,j;i<=min(x,y);i=j+1)
{
j=min(x/(x/i),y/(y/i));
ret+=1LL*(g[j]-g[i-1])*(x/i)*(y/i);
}
return ret;
}
int main()
{
int tot=0;
range(i,2,MAXN+1)
{
if(!flag[i]) pr[tot++]=i,las[i]=cnt[i]=g[i]=1;
range(j,0,tot)
{
int x=i*pr[j];
if(x>MAXN) break;
flag[x]=1;
if(i%pr[j]==0)
{
las[x]=las[i],cnt[x]=cnt[i]+1,
g[x]=(las[x]==1?1:-g[las[x]]*(cnt[las[x]]==cnt[x]));
break;
}
las[x]=i,cnt[x]=1,g[x]=-g[i]*(cnt[i]==1);
}
}
range(i,1,MAXN+1) g[i]+=g[i-1];
for(int T=getU();T--;)
{
int x=getU(),y=getU(); putLL(solve(x,y),'\n');
}
return 0;
}
SCP-bzoj-3309的更多相关文章
- ●BZOJ 3309 DZY Loves Math
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...
- bzoj 3309 反演
$n=p_1^{a_1}p_2^{a_2}…p_k^{a_k},p_i$为素数,定义$f(n)=max(a_1,a_2…,a_k)$. 给定a,b<=1e7求$\sum\limits_{i=1} ...
- BZOJ 3309: DZY Loves Math
3309: DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 761 Solved: 401[Submit][Status ...
- 【BZOJ 3309】DZY Loves Math
http://www.lydsy.com/JudgeOnline/problem.php?id=3309 \[\sum_{T=1}^{min(a,b)}\sum_{d|T}f(d)\mu(\frac ...
- BZOJ 3309 莫比乌斯反演
题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3309 题意:定义f(n)为n所含质因子的最大幂指数,求 $Ans=\sum _{i=1} ...
- bzoj 3309 DZY Loves Math——反演+线性筛
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 像这种数据范围,一般是线性预处理,每个询问 sqrt (数论分块)做. 先反演一番.然 ...
- bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...
- 数学(数论)BZOJ 3309:DZY Loves Math
Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0. 给定正整数a,b, ...
- BZOJ 3309: DZY Loves Math [莫比乌斯反演 线性筛]
题意:\(f(n)\)为n的质因子分解中的最大幂指数,求\(\sum_{i=1}^n \sum_{j=1}^m f(gcd(i,j))\) 套路推♂倒 \[ \sum_{D=1}^n \sum_{d| ...
- 【bzoj 3309 】 DZY Loves Math
Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0.给定正整数a,b,求 ...
随机推荐
- SQL Server索引管理之六大铁律
索引是以表列为基础的数据库对象.索引中保存着表中排序的索引列,并且纪录了索引列在数据库表中的物理存储位置,实现了表中数据的逻辑排序.通过索引,可以加快数据的查询速度和减少系统的响应时间;可以使表和表之 ...
- Python3解leetcode Factorial Trailing Zeroes
问题描述: Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 ...
- php is_file()函数 语法
php is_file()函数 语法 is_file()函数怎么用? php is_file()函数用于判断给定文件名是否为一个正常的文件,语法是bool is_file ( string $file ...
- npm和webpack安装以及相关信息
一.npm初始化 在项目文件夹下执行npm init,根据提示回车或者填写信息.结果是生成packge.json文件. 根据json文件npm install会安装依赖,项目会看到有一个node_mo ...
- paper 166:梯度下降法及其Python实现
参考来源:https://blog.csdn.net/yhao2014/article/details/51554910 梯度下降法(gradient descent),又名最速下降法(steepes ...
- PWN入门的入门——工具安装
安装pwntool: 命令行运行: pip install pwntools python import pwn pwn.asm("xor eax,eax") 出现'1\xc0' ...
- 2-prometheus各组件安装
相关下载: https://prometheus.io/download/https://github.com/prometheus/ 相关文档 https://songjiayang.gitbook ...
- Chrome-谷歌页面翻译增强插件开发
最近想做一个 Chrome 的插件(看别的博客说其实叫插件不准确,应该叫拓展,大家叫习惯了就按习惯的来吧).一开始咱先直接看了[Chrome 开发(360 翻译)](http://open.chrom ...
- crontab 使用
1. 安装,结构 yum install cronie 结构: * * * * * [分钟] [小时] [每月的某一天] [每年的某一月] [每周的某一天] 2.命令 1,添加或更新crontab中的 ...
- 家用NAS配置方案
对家用用户而言,NAS即一台下载机,硬件需要满足以下几点: 1.稳定性:24×7稳定无故障运行. 2.拓展性:较多的硬盘槽位,便于容量扩容: 3.体积小巧:占地面积小,便于放置. 4.方便远程管理:无 ...