$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}^{a}\sum\limits_{j=1}^{b}f((i,j))$

先简化。

\begin{eqnarray*} \sum\limits_{i=1}^{a}\sum\limits_{j=1}^{b}f((i,j)) &=& \sum_{d=1}^{min(a,b)}\sum\limits_{i=1}^{a}\sum\limits_{j=1}^{b}f(d)[(i,j)=d] \newline &=& \sum_{d=1}^{min(a,b)}\sum\limits_{i=1}^{\lfloor \frac{a}{d} \rfloor}\sum\limits_{j=1}^{\lfloor \frac{a}{d} \rfloor}f(d)[(i,j)=1] \newline &=& \sum\limits_{{\rm{d = 1}}}^{\min (a,b)} {\sum\limits_{i = 1}^{\left\lfloor {\frac{a}{d}} \right\rfloor } {\sum\limits_{j = 1}^{\left\lfloor {\frac{b}{d}} \right\rfloor } {\sum\limits_{k|(i,j)}^{} {\mu (k)f(d)} } } } \newline  &=& \sum\limits_{d = 1}^{\min (a,b)} {\sum\limits_{k = 1}^{\min (\left\lfloor {\frac{a}{d}} \right\rfloor ,\left\lfloor {\frac{b}{d}} \right\rfloor )} {f(d)\mu (k)} \left\lfloor {\frac{a}{{kd}}} \right\rfloor \left\lfloor {\frac{b}{{kd}}} \right\rfloor }  \newline &=& \sum\limits_{T = kd = 1}^{\min (a,b)} {\sum\limits_{d|T}^{} {f(d)\mu (\frac{T}{d})} \left\lfloor {\frac{a}{T}} \right\rfloor \left\lfloor {\frac{b}{T}} \right\rfloor } \newline \end{eqnarray*}

所以只要能够预处理出$\sum\limits_{d|T} {f(d)\mu (\frac{T}{d})}$就能分块了。

注意观察该函数,根据$f()$取素因子次数的最大值及$\mu()$数论意义上的容斥性质,可以发现当$a_i$的值都一样时,才存在一个次数的组合使$\frac{T}{d}=p_1^{1}p_2^{1}…p_k^{1}$值无法被消去,因为它的$f()$值要比对称的组合$f(p_1^{0}p_2^{0}…p_k^{0})$大1,而其他的所有组合都可找到一个素因子数量对称的组合使得两者的$\mu$互为相反数而相消。

故最后$\sum\limits_{d|T} {f(d)\mu (\frac{T}{d})}=(-1)^{k+1}$

线性筛里处理数论函数。预处理其前缀和就好了。

/** @Date    : 2017-09-28 21:09:51
* @FileName: bzoj 3309 反演.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e6+20;
const double eps = 1e-8; int c = 0;
bool vis[N*10];
int pri[N]; int cnt[N*10];
int k[N*10];
int f[N*10]; void prime()
{
MMF(vis);
for(int i = 2; i < 10000010; i++)
{
if(!vis[i])
{
pri[c++] = i;
cnt[i] = 1;
k[i] = i;//最小的素因子对应的幂
f[i] = 1;
}
for(int j = 0; j < c && i * pri[j] < 10000010; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0)//倍数
{
cnt[i * pri[j]] = cnt[i] + 1;//最小质因子次数+1
k[i * pri[j]] = k[i] * pri[j];//幂增大1次
int tmp = i / k[i];//除去该因子的幂
if(tmp == 1)
f[i * pri[j]] = 1;//说明只有一个因子
else f[i * pri[j]] = (cnt[tmp]==cnt[i * pri[j]]?-f[tmp]:0);//判断次数是否相同
break;
}
else
{
cnt[i * pri[j]] = 1;//首次出现默认次数为1
k[i * pri[j]] = pri[j];//
f[i * pri[j]] = (cnt[i]==1?-f[i]:0);
}
/*getchar();
cout << i<<"~~"<<i * pri[j] << "~"<<k[i * pri[j]] <<endl;
cout << cnt[i * pri[j]] << endl;*/
}
}
for(int i = 1; i < 10000010; i++)
f[i] += f[i - 1];
}
int main()
{
int T;
prime();
cin >> T;
while(T--)
{
LL a, b;
scanf("%lld%lld", &a, &b);
if(a > b)
swap(a, b);
LL ans = 0;
for(int i = 1, last; i <= a; i = last + 1)
{
last = min(a/(a/i), b/(b/i));
ans += (a / i) * (b / i) * (f[last] - f[i - 1]);
}
printf("%lld\n", ans);
}
return 0;
}

bzoj 3309 反演的更多相关文章

  1. ●BZOJ 3309 DZY Loves Math

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

  2. BZOJ 3309 莫比乌斯反演

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

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

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

  4. BZOJ 3309 DZY Loves Math ——莫比乌斯反演

    枚举$d=gcd(i,j)$ 然后大力反演 ——来自Popoqqq的博客. 然后大力讨论后面的函数的意义即可. http://blog.csdn.net/popoqqq/article/details ...

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

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

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

  7. bzoj 3309 DZY Loves Math 莫比乌斯反演

    DZY Loves Math Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1303  Solved: 819[Submit][Status][Dis ...

  8. BZOJ 3309: DZY Loves Math 莫比乌斯反演+打表

    有一个神奇的技巧——打表 code: #include <bits/stdc++.h> #define N 10000007 #define ll long long #define se ...

  9. BZOJ 3309: DZY Loves Math

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

随机推荐

  1. 【转】python 三种遍历list的方法

    [转]python 三种遍历list的方法 #!/usr/bin/env python # -*- coding: utf-8 -*- if __name__ == '__main__': list ...

  2. TensorFlow问题“Attempting to use uninitialized value”

    1.出现的问题: 对已经保存好的模型,在进行重载并继续训练的过程中出现了以下问题: 2.解决办法: 在查找了相关资料后,了解到,该错误是指在从tfrecord中读取数据时一些参数未被初始化,如果直接r ...

  3. sleep与信号唤醒的问题 & 内核对信号的处理方式 & udelay

    http://www.cnblogs.com/charlesblc/p/6277848.html 注意,sleep是会被信号唤醒的.   sleep函数:#include <unistd.h&g ...

  4. Internet History, Technology and Security (Week 1)

    Week 1 History: Dawn of Electronic Computing Welcome to Week 1! This week, we'll be covering the ear ...

  5. JabRef学习笔记(一)

    JabRef简介 JabRef is an open source bibliography reference manager. The native file format used by Jab ...

  6. PAT 1053 住房空置率

    https://pintia.cn/problem-sets/994805260223102976/problems/994805273284165632 在不打扰居民的前提下,统计住房空置率的一种方 ...

  7. 微信小程序 功能函数 把数字1,2,3,4换成春,夏,秋,冬

    let season =‘1,2,3’; // console.log(season.length) if (season){ if (season.length==1){ seasonChe1=se ...

  8. Delphi开发单机瘦数据库程序要点(后缀cds)

    一.概述 Delphi作为Windows下的一种快速开发工具,不仅能开发一般的Windows应用程序,而且还具有强大的数据库应用程序开发功能.Delphi本身提供了对BDE,ODBC,ADO和Inte ...

  9. sql中的duplicate的使用

    应用场景:有时候在做一些系统设置功能的时候,系统在第一次使用,或者初始化的时候,该设置信息并没有存在于数据库中,或者该系统设置信息永远只保存一条,没有必要为增加和修改这条信息而分别编写insert和u ...

  10. POJ3281_Dining

    有一些饮料和食物,每种一个,每个客人喜欢一些饮料和一些食物,每个客人可以选择一种饮料和一种食物,问最多能够同时满足多少个客人同时拥有饮料和食物. 这样的,源点连接饮料,汇点连接食物,中间人分别连接饮料 ...