HDU 5528 反演
$f(m)=\sum\limits_{i=1}^{m-1}\sum\limits_{j=1}^{m-1}[(ij,m) \ne m]$,$g(n)=\sum\limits_{m|n}f(m)$,$1 \le n \le 10^9$,求$g(n)$模$2^{64}$。
要求为$i j ∤ m$,说明$ij$不为$m$的倍数,但是可以有公共因子,直接求很麻烦,不如先反着来求不符合的,最后再减掉。然后就是化式子,枚举一个数$(m, i)=d$,则另一个数满足$\frac{m}{d}|j$,二者各自有$\varphi(\frac{m}{d})$和$d$个数量,继续化简,之后可以观察到右半式就是某很经典的欧拉函数的结论,然后预处理素数,素因子分解计算下贡献,最后左右两个半式相减就行了。
\begin{eqnarray*} g(n) &=& \sum\limits_{m|n}(m^2-\sum\limits_{i=1}^{m-1}\sum\limits_{j=1}^{m-1}[(ij,m) = m]) \newline &=&\sum\limits_{m|n} {m^2} - \sum\limits_{m|n} \sum\limits_{d|m} d\varphi \left( \frac{m}{d} \right) \newline &=& \sum\limits_{m|n} {m^2} - \sum\limits_{d|n}d {\sum\limits_{\frac{m}{d}|\frac{n}{d}} {\varphi \left( {\frac{m}{d}} \right)} } \newline &=& \sum\limits_{m|n} {m^2} - \sum\limits_{d|n}{d \frac{n}{d}} \newline &=& \sum\limits_{m|n} {m^2} - n \sum\limits_{d|n}{1} = \sum\limits_{m|n} {m^2} - n \tau(n) \end{eqnarray*}
还有另外一种方法就是直接利用积性函数的性质,再用欧拉函数化简。得到的最后式子是一样的。
/** @Date : 2017-10-20 14:18:28
* @FileName: HDU 5528 反演.cppc
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL unsigned 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 = 5e4+20;
const double eps = 1e-8; LL pri[N];
bool vis[N];
int c = 0; void prime()
{
MMF(vis);
for(int i = 2; i < N; i++)
{
if(!vis[i]) pri[c++] = i;
for(int j = 0; j < c && i * pri[j] < N; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0) break;
}
}
} int main()
{
prime();
int T;
scanf("%d", &T);
while(T--)
{
LL n;
scanf("%llu", &n);
LL t = n;
LL sum = 1ULL, dis = 1ULL;
for(int i = 0; i < c && pri[i] * pri[i] <= t; i++)
{
if(t % pri[i] == 0)
{
LL cnt = 1;
LL tmp = 1ULL;
LL k = 1ULL;
while(t % pri[i] == 0)
t /= pri[i], cnt++; for(int j = 0; j < cnt - 1; j++)
{
tmp *= pri[i];
k += (LL)tmp * tmp;// ()* m^2
}
sum *= k;
dis *= cnt;
}
}
if(t > 1)
{
sum *= t * t + 1;
dis *= 2ULL;
}
dis *= n;
printf("%llu\n", sum - dis);
}
return 0;
}
HDU 5528 反演的更多相关文章
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- HDU 5528 Count a * b 欧拉函数
题意: 定义函数\(f(n)\)为\(i \cdot j \not\equiv 0 \; (mod \; n)\)的数对\((i,j)\)的个数\((0 \leq i,j \leq n)\) \(g( ...
- HDU 5514 Frogs 欧拉函数
题意: 有\(m(1 \leq m \leq 10^9)\)个石子排成一圈,编号分别为\(0,1,2 \cdots m-1\). 现在在\(0\)号石头上有\(n(1 \leq n \leq 10^4 ...
- HDU 2841 Visible Trees(莫比乌斯反演)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...
- HDU 5321 Beautiful Set (莫比乌斯反演 + 逆元 + 组合数学)
题意:给定一个 n 个数的集合,然后让你求两个值, 1.是将这个集合的数进行全排列后的每个区间的gcd之和. 2.是求这个集合的所有的子集的gcd乘以子集大小的和. 析:对于先求出len,len[i] ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2841 容斥 或 反演
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...
- hdu 4676 Sum Of Gcd 莫队+phi反演
Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of ...
- HDU 6134 Battlestation Operational(莫比乌斯反演)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6134 [题目大意] 求$\sum_{i=1}^{n}{\sum_{j=1}^{i}\lceil{\ ...
随机推荐
- 设计模式 笔记 解释器模式 Interpreter
//---------------------------15/04/26---------------------------- //Interpreter 解释器模式----类行为型模式 /* 1 ...
- 【翻译】Brewer's CAP Theorem CAP定理
Brewer's CAP Theorem 原文地址:http://www.julianbrowne.com/article/brewers-cap-theorem Brewer’s (CAP) The ...
- MFC Cstring转化为string
Cstring m_filePath; string sname( CW2A( m_filePath.GetString())); http://blog.sina.com.cn/s/blog_530 ...
- Java 笔记——MyBatis 生命周期
1.MyBatis 的生命周期 MyBatis的核心组件分为4个部分. SqlSessionFactoryBuilder (构造器): 它会根据配置或者代码来生成SqISessionFactory,采 ...
- ElasticSearch 2 (7) - 基本概念
ElasticSearch 2 (7) - 基本概念 摘要 ElasticSearch的一些基本核心概念,理解这些概念有助于ElasticSearch的学习 准实时NRT(Near Realtime) ...
- Python爬虫:抓取新浪新闻数据
案例一 抓取对象: 新浪国内新闻(http://news.sina.com.cn/china/),该列表中的标题名称.时间.链接. 完整代码: from bs4 import BeautifulSou ...
- git 生成秘钥
Permission denied (publickey). fatal: The remote end hung up unexpectedly 应该是ssh key过期了吧 试着重新创建ssh k ...
- vsphere web client 使用中文的解决办法
1. 很多网站这么说的: vsphere web client的默认URL为:https://hostname:9443/vsphere-client 可以在URL后面加上一个参数来指定区域语言 英语 ...
- adb 安装apk报INSTALL_FAILED_NO_MATCHING_ABIS
想在模拟器中安装搜狗拼音输入法,结果安装的时候报错:INSTALL_FAILED_NO_MATCHING_ABIS 上网搜索发现解决方法如下: 原博客:使用Genymotion调试出现错误INSTAL ...
- 获取移动端 touchend 事件中真正触摸点下方的元素
移动端的touchstart, touchmove, touchend三个事件,拖动元素结束时,获取到了touchend事件, 但是event.touches[0].target所指向的元素却是tou ...