就让我这样的蒟蒻发一个简单易想的题解吧!!!

  这题我一开始一看,woc这不是莫比乌斯反演么,推推推,推到杜教筛,输出结果一看不对

  emmm回来仔细想想……woc推错了?

  然后撕烤半天打了个暴力,A了

  首先我们学过莫比乌斯反演的一般能够想到枚举gcd,记为w

  所以我们需要求的就是$\sum\limits_{w|n}w\sum\limits_{w|i}[gcd(i,n)=w]$

  然后……就到了激动人心的构造函数环节……

  设$F(w)=\sum\limits_{w|i}[w|gcd(i,n)]$

  $f(w)=\sum\limits_{w|i}[w=gcd(i,n)]$

  于是有$F(w)=\sum\limits_{w|d}f(d)$

  于是……$f(w)=\sum\limits_{w|d}\mu(\frac{d}{w})F(d)$

  容易(个屁,我手玩了半年)发现,当$d|n$时$F(d)=\frac{n}{d}$,其他情况下$F(d)=0$

  然后问题就变成了$\sum\limits_{w|n}w\sum\limits_{w|d}\mu(\frac{d}{w})F(d)$

  设$t=\frac{d}{w}$

  原式化为$\sum\limits_{w|n}w\sum\limits_{t|d}\mu(t)F(tw)$

  然后我们发现了什么?

  没错w可以暴力枚举qwq!没错t可以暴力枚举qwq!

  因为我们枚举到根n就可以枚举出n的所有因子!  t同理!

  来吧让我们暴……等等$\mu$怎么算?

  废话啊按着莫比乌斯函数的定义暴力qwq!

  

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iostream>
#include<cmath>
#define maxn 5000020
using namespace std;
inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} bool vis[maxn];
int prime[maxn],tot;
int mu[maxn]; inline int calcmu(long long n){
if(n<maxn) return mu[n];
long long sqt=sqrt(n);
long long now=n;int ans=;
for(int j=;j<=tot;++j){
int i=prime[j];
if(i>sqt) break;
if(now%i) continue;
int cnt=;
while((now%i)==){
cnt++; now/=i;
if(cnt>) return ;
}
ans++;
}
if(now>) ans++;
if(ans&) return -;
else return ;
} int main(){
mu[]=vis[]=;
for(int i=;i<maxn;++i){
if(vis[i]==){
prime[++tot]=i;
mu[i]=-;
}
for(int j=;j<=tot&&prime[j]*i<maxn;++j){
vis[i*prime[j]]=;
if(i%prime[j]) mu[i*prime[j]]=-mu[i];
else break;
}
}
long long n=read(),ans=;
int sqt=sqrt(n);
for(int i=;i<=sqt;++i){
if(n%i) continue;
long long d=n/i;long long now=;
long long sar=sqrt(d);
for(int j=;j<=sar;++j){
if(d%j) continue;
now+=calcmu(j)*(n/(j*i));
if(j*j==d) continue;
now+=calcmu(d/j)*(n/((d/j)*i));
}
ans+=now*i; if(1LL*i*i==n) continue;
long long ret=n/i;
d=n/ret;now=;
sar=sqrt(d);
for(int j=;j<=sar;++j){
if(d%j) continue;
now+=calcmu(j)*(n/(j*ret));
if(j*j==d) continue;
now+=calcmu(d/j)*(n/((d/j)*ret));
}
ans+=now*ret;
}
printf("%lld\n",ans);
return ;
}

【Luogu】P2303Longge的问题(莫比乌斯反演)的更多相关文章

  1. BZOJ 3930 Luogu P3172 选数 (莫比乌斯反演)

    手动博客搬家:本文发表于20180310 11:46:11, 原地址https://blog.csdn.net/suncongbo/article/details/79506484 题目链接: (Lu ...

  2. [Luogu P3455] [POI2007]ZAP-Queries (莫比乌斯反演 )

    题面 传送门:洛咕 Solution 这题比这题不懂简单到哪里去了 好吧,我们来颓柿子. 为了防止重名,以下所有柿子中的\(x\)既是题目中的\(d\) 为了方便讨论,以下柿子均假设\(b>=a ...

  3. 【Luogu】P3455Zip-Queries(莫比乌斯反演)

    题目链接 真是神TM莫比乌斯 首先来看一个神奇的结论:求gcd(x,y)==k的对数,其中1<=x<=n,1<=y<=m 等同于求gcd(x,y)==1的对数,其中1<= ...

  4. 【Luogu】P2522Problemb(莫比乌斯反演)

    题目链接 同Zip—Queries,但是用到容斥原理 设f(n,m)是(x,y)的对数,其中1<=x<=n,1<=y<=m 则有f(n,m)-f(a-1,n)-f(b-1,m) ...

  5. BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)

    手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...

  6. [jzoj 6084] [GDOI2019模拟2019.3.25] 礼物 [luogu 4916] 魔力环 解题报告(莫比乌斯反演+生成函数)

    题目链接: https://jzoj.net/senior/#main/show/6084 https://www.luogu.org/problemnew/show/P4916 题目: 题解: 注: ...

  7. [luogu P2586] GCD 解题报告 (莫比乌斯反演|欧拉函数)

    题目链接:https://www.luogu.org/problemnew/show/P2568#sub 题目大意: 计算​$\sum_{x=1}^n\sum_{y=1}^n [gcd(x,y)==p ...

  8. BZOJ 5330 Luogu P4607 [SDOI2018]反回文串 (莫比乌斯反演、Pollard Rho算法)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=5330 (Luogu) https://www.luogu.org/prob ...

  9. [Luogu P1829] [国家集训队]Crash的数字表格 / JZPTAB (莫比乌斯反演)

    题面 传送门:洛咕 Solution 调到自闭,我好菜啊 为了方便讨论,以下式子\(m>=n\) 为了方便书写,以下式子中的除号均为向下取整 我们来颓柿子吧qwq 显然,题目让我们求: \(\l ...

随机推荐

  1. ceisum_加载倾斜摄影模型

    osgb转换为3Dtiles格式(使用工具转换) 然后加载到cesium中(加载代码见下,可以控制模型高度) var offset = function(height,tileset) { conso ...

  2. MovieReview—Ghost in the Shell 2: Innocence(攻壳机动队2:无罪)

    Doll killing event            The movie was developed around a series of doll murders. Barthes and o ...

  3. k8s1.13.0二进制部署-master节点(三)

    部署apiserver 创建生成CSR的JSON配置文件 [root@k8s-master1 ssl]# vim kubernetes-csr.json { "CN": " ...

  4. targetcli save error

    iscsi configuration unable to save python error “ValueError: 'Implict and Explict' is not in list” / ...

  5. 怎样将Oracle数据库设置为归档模式及非归档模式

    怎样将Oracle数据库设置为归档模式及非归档模式 1.Oracle日志分类 分三大类: Alert log files--警报日志,Trace files--跟踪日志(用户和进程)和 redo lo ...

  6. 记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名!

    // 记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名! var username = document.getElementById("username&quo ...

  7. NOIP复习之1 数学数论

    noip一轮复习真的要开始啦!!! 大概顺序是这样的 1.数学 2.搜索贪心 3.数据结构 4.图论 5.dp 6.其他 数学 1.数论 数论被称为数学皇冠上的明珠,他的重要性主要在于它是其他学习的祖 ...

  8. mysql EOF

    mysql shell 执行脚本 #!/bin/bash export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql-5.6/bin:/usr ...

  9. 地理位置编码geohash学习笔记

    1.geohash及其性质 一种空间索引技术. (1)将二维的经纬度位置数据转换为一维的字符串(基本上hash族的算法都是这样): 其优点在于hash编码后的字符串,可以方便查找和索引,从而减少相似计 ...

  10. destoon 配置文件config.inc.php参数说明

    $CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...