[ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]
题目链接:Easy Math
题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum_{i=1}^{m}\mu (i\cdot n)\)。
题解:废话少说,直接上公式
$$\mu(i\cdot n)=\left\{\begin{matrix}
\mu(i)\cdot\mu(n) & gcd(i,n)==1\\
0 & other
\end{matrix}\right.$$
设
$$F(n,m)=\sum_{i=1}^{m}\mu(i\cdot n)$$
则有$$F(n,m)=\mu(n)\cdot\sum_{i=1}^{m}\mu (i)\cdot[gcd(i,n)==1]$$
由$$[n==1]=\sum_{d|n}^{ } \mu(d)$$
$$F(n,m)=\mu(n)\cdot\sum_{i=1}^{m}\mu (i)\sum_{d|gcd(i,n)}^{ }\mu(d)$$
$$F(n,m)=\mu(n)\cdot\sum_{d|n}^{d\leqslant m}\mu(d)\cdot\sum_{i=1}^{\left \lfloor \frac{m}{d} \right \rfloor}\mu(i\cdot d)$$
$$F(n,m)=\mu(n)\cdot\sum_{d|n}^{d\leqslant m}\mu(d)\cdot F(d,\left \lfloor \frac{m}{d} \right \rfloor)$$
推出式子后,递归求解即可,当n==1时,有\(F(n,m)=M(m)=\sum_{i=1}^{m}\mu(i)\),关于这个式子有一个莫比乌斯反演的经典公式,就是$$M(n)=1-\sum_{i=2}^{n}M(\left \lfloor \frac{n}{i} \right \rfloor)$$预处理出莫比乌斯函数及其前缀和的值后即可,求M(n)的时候记得要分块做
#include<bits/stdc++.h>
using namespace std;
#define N 10000001
#define LL long long
LL n,m,cnt,p[N],f[N],s[N];
map<LL,LL>M;
bool x[N];
void pretype()
{
f[]=;
for(int i=;i<N;i++)
{
if(!x[i])p[++cnt]=i,f[i]=-;
for(int j=;j<=cnt && i*p[j]<N;j++)
{
f[i*p[j]]=-f[i];
x[i*p[j]]=true;
if(i%p[j]==){f[i*p[j]]=;break;}
}
}
for(int i=;i<N;i++)
s[i]=s[i-]+f[i];
}
LL get(LL n)
{
if(n<N)return f[n];
LL k=;
for(LL i=;i*i<=n;i++)
if(n%i==)
{
if(n%(i*i)==)return ;
k*=-,n/=i;
}
if(n>)k*=-;return k;
}
LL get_M(LL n)
{
if(n<N)return s[n];
if(M[n])return M[n];
LL res=,nxt;
for(LL i=;i<=n;i=nxt+)
{
nxt=min(n,n/(n/i));
res-=(nxt-i+)*get_M(n/i);
}
return M[n]=res;
}
LL F(LL n,LL m)
{
if(n==)return get_M(m);
LL miu=get(n),res=;
if(miu==)return ;
for(LL d=;d*d<=n && d<=m;d++)if(n%d==)
{
res+=get(d)*F(d,m/d);
if(n/d<=m)res+=get(n/d)*F(n/d,m/(n/d));
}
return miu*res;
}
int main()
{
pretype();
scanf("%lld%lld",&m,&n);
printf("%lld\n",F(n,m));
}
[ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]的更多相关文章
- 徐州赛区网络预赛 D Easy Math
比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA.回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子, ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
- ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash
Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...
随机推荐
- Spring中Mybatis的花样配置 及 原理
摘自: https://www.jianshu.com/p/fc23c94fc439
- Python实现多进程
Python可以实现多线程,但是因为Global Interpreter Lock (GIL),Python的多线程只能使用一个CPU内核,即一个时间只有一个线程在运行,多线程只是不同线程之间的切换, ...
- git reflog
http://www.softwhy.com/article-8573-1.html https://www.cnblogs.com/irocker/p/git-reflog.html https:/ ...
- 小程序学习笔记二:页面文件详解之 .json文件
页面配置文件—— pageName.json 每一个小程序页面可以使用.json文件来对本页面的窗口表现进行配置,页面中配置项会覆盖 app.json 的 window 中相同的配置项. 页面的 ...
- docker 端口映射 及外部无法访问问题
docker容器内提供服务并监听8888端口,要使外部能够访问,需要做端口映射. docker run -it --rm -p : server:v1 此时出现问题,在虚机A上部署后,在A内能够访问8 ...
- Implementation of Message Receiver
- Linux服务器CPU使用率较低但负载较高
CPU使用率较低但负载较高 问题描述 Linux 系统没有业务程序运行,通过 top 观察,类似如下图所示,CPU 很空闲,但是 load average 却非常高,如下图所示. 处理办法 load ...
- Unity3D修改LWRP,HDRP的几项小问题及解决
最近在看Book of the Dead的demo,其中对HDPR进行修改以构建自己的SRP,于是自己尝试了下.. 一般直接去Github下载对应unity版本的SRP工程: https://gith ...
- 基于Vue element-ui实现支持多级纵向动态表头的仿表格布局
[本文出自天外归云的博客园] 需求图示如下,多级纵向动态表头表格: 我的思路是用element-ui的layout实现,做出一个仿造表格,能够支持动态的.多级的.纵向的表头: <template ...
- 什么是面向切面编程AOP--知识点汇总
最近在学这方面的内容,读到的这段话我感觉说的很清楚了:这种在运行时,动态地将代码切入到类的指定方法.指定位置上的编程思想就是面向切面的编程. 面向切面编程(AOP是Aspect Orie ...