####
**项目编号:bzoj-3309**

项目等级:Safe

项目描述:

戳这里

特殊收容措施:

以下用$(x, y)$表示$gcd(x, y)$。

$$
ans = \sum _ {i = 1} ^ {a}
\sum _ {j = 1} ^ {b}
f((i, j))
= \sum _ {g = 1} ^ {min(a, b)} f(g)
\sum _ {i = 1} ^ {\lfloor {\frac a g} \rfloor}
\sum _ {j = 1} ^ {\lfloor {\frac b g} \rfloor}
\epsilon((i, j))
$$

又有$\epsilon = \mu * 1$,故

$$
ans = \sum _ {g = 1} ^ {min(a, b)} f(g)
\sum _ {i = 1} ^ {\lfloor {\frac a g} \rfloor}
\sum _ {j = 1} ^ {\lfloor {\frac b g} \rfloor}
\sum _ {d | i, d | j} \mu(d)
= \sum _ {g = 1} ^ {min(a, b)} f(g)
\sum _ {d = 1} ^ {min(\lfloor {\frac a g} \rfloor, \lfloor {\frac b g} \rfloor)}
\mu(d) \lfloor {\frac a {d g}} \rfloor \lfloor {\frac b {d g}} \rfloor
$$

设$T = d g$,则

$$
ans = \sum _ {T = 1} ^ {min(a, b)}
\lfloor {\frac a T} \rfloor \lfloor {\frac b T} \rfloor
\sum _ {g | T} f(g) \mu(\frac T 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的更多相关文章

  1. ●BZOJ 3309 DZY Loves Math

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...

  2. 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} ...

  3. BZOJ 3309: DZY Loves Math

    3309: DZY Loves Math Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 761  Solved: 401[Submit][Status ...

  4. 【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 ...

  5. BZOJ 3309 莫比乌斯反演

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3309 题意:定义f(n)为n所含质因子的最大幂指数,求 $Ans=\sum _{i=1} ...

  6. bzoj 3309 DZY Loves Math——反演+线性筛

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 像这种数据范围,一般是线性预处理,每个询问 sqrt (数论分块)做. 先反演一番.然 ...

  7. bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...

  8. 数学(数论)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, ...

  9. 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| ...

  10. 【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,求 ...

随机推荐

  1. Codeforces 831C--Jury Marks (思维)

    题目链接:http://codeforces.com/problemset/problem/831/C 题意:有一位参赛选手,我们不知道他初始或最后的成绩,但是知道k次评审所加(减)的分数,以及n个在 ...

  2. webservice文件上传下载(byte[] 实现方式)

    测试环境:axis2-1.6.1.6.0.20.jdk1.5 说明:本方式仅适用于文件小于10M的场景(否则会出现内存溢出),大文件的上传下载应另选其他方式. 1.创建要发布成webservice的j ...

  3. paper 154:姿态估计(Hand Pose Estimation)相关总结

    Awesome Works  !!!! Table of Contents Conference Papers 2017 ICCV 2017 CVPR 2017 Others 2016 ECCV 20 ...

  4. 2019.6.1 模拟赛——[ 费用流 ][ 数位DP ][ 计算几何 ]

    第一题:http://codeforces.com/contest/1061/problem/E 把点集分成不相交的,然后跑费用流即可.然而错了一个点. #include<cstdio> ...

  5. 前端每日实战:46# 视频演示如何用纯 CSS 创作一个在容器中反弹的小球

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/jKVbyE 可交互视频教程 此视频 ...

  6. jsp的课设1

    记这个为了巩固整个网站的开发流程,java开发太昂贵基本上很少有公司用,不知道学校怎么想的用这个.基本流程适用于任何后台的开发. JDK的安装不提了,Tomcat和Mysql都是用的最新版的,由于是w ...

  7. codeforces 557D Vitaly and Cycle

    题意简述 给定一个图 求至少添加多少条边使得它存在奇环 并求出添加的方案数 (注意不考虑自环) ---------------------------------------------------- ...

  8. App知识点(持续更新......)

    1.app的性能测试,即专项测试,需要重点关注那些方面? 内存.cpu占用.耗电量.流量.流畅度等 2.什么是activity?它的生命周期? Activity是一个Android的应用组件,它提供屏 ...

  9. POJ1426-Find The Multiple-bfs

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repr ...

  10. git使用记录二: 给文件重命名的简单方法

    git使用记录三: 给文件重命名的简单方法 git mv file_name_old file_name_new mv: 文件命名 file_name_old : 文件当前的名字 file_name_ ...