没啥好说的,杜教筛板子题。

\[\sum_{i=1}^{N} \sum_{j=1}^{N}\sum_{p=1}^{\lfloor \frac{N}{j} \rfloor}\sum_{q=1}^{\lfloor \frac{N}{j} \rfloor} [\gcd(i,j)==1][\gcd(p,q)==1]
\]

容易发现,我们枚举 \(j\) 其实是相当于枚举 \(\gcd\)

才不是枚举题目

然后式子可以变成

\[\sum_{i=1}^{N}\sum_{p=1}^{N}\sum_{q=1}^{N} [\gcd(i,p,q)==1]
\]

然后套路式的枚举 \(gcd\) 依旧不是枚举题目

\[\sum_{d=1}^{N}\sum_{i=1}^{N}\sum_{p=1}^{N}\sum_{q=1}^{N}[\gcd(i,p,q)==d]
\]

熟悉的形式,其实就等于

\[\sum_{d=1}^{N}\sum_{i=1}^{\lfloor \frac{N}{d} \rfloor} \sum_{p=1}^{\lfloor \frac{N}{d} \rfloor} \sum_{q=1}^{\lfloor \frac{N}{d} \rfloor} \mu(d)
\]

\[\sum_{d=1}^{N} \mu(d) \lfloor \frac{N}{d}\rfloor^3
\]

然后整除分块就完了,由于 \(N\) 比较大,大力杜教筛就完事了,话说我好像是这题除掉出题人的最优解

// powered by c++11
// by Isaunoya
#include<bits/stdc++.h>
#define rep(i , x , y) for(register int i = (x) ; i <= (y) ; ++ i)
#define Rep(i , x , y) for(register int i = (x) ; i >= (y) ; -- i)
using namespace std ;
using db = double ;
using ll = long long ;
using uint = unsigned int ;
#define int long long
using pii = pair < int , int > ;
#define ve vector
#define Tp template
#define all(v) v.begin() , v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
#define fir first
#define sec second
// the cmin && cmax
Tp < class T > void cmax(T & x , const T & y) { if(x < y) x = y ; }
Tp < class T > void cmin(T & x , const T & y) { if(x > y) x = y ; }
// sort , unique , reverse
Tp < class T > void sort(ve < T > & v) { sort(all(v)) ; }
Tp < class T > void unique(ve < T > & v) { sort(all(v)) ; v.erase(unique(all(v)) , v.end()) ; }
Tp < class T > void reverse(ve < T > & v) { reverse(all(v)) ; }
const int SZ = 0x191981 ;
struct FILEIN {
~ FILEIN () {} char qwq[SZ] , * S = qwq , * T = qwq , ch ;
char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq , 1 , SZ , stdin) , S == T) ? EOF : * S ++ ; }
FILEIN & operator >> (char & c) { while(isspace(c = GETC())) ; return * this ; }
FILEIN & operator >> (string & s) {
while(isspace(ch = GETC())) ; s = ch ;
while(! isspace(ch = GETC())) s += ch ; return * this ;
}
Tp < class T > void read(T & x) {
bool sign = 1 ; while((ch = GETC()) < 0x30) if(ch == 0x2d) sign = 0 ;
x = (ch ^ 0x30) ; while((ch = GETC()) > 0x2f) x = x * 0xa + (ch ^ 0x30) ;
x = sign ? x : -x ;
}
FILEIN & operator >> (int & x) { return read(x) , * this ; }
FILEIN & operator >> (signed & x) { return read(x) , * this ; }
FILEIN & operator >> (unsigned & x) { return read(x) , * this ; }
} in ;
struct FILEOUT { const static int LIMIT = 0x114514 ;
char quq[SZ] , ST[0x114] ; signed sz , O ;
~ FILEOUT () { sz = O = 0 ; }
void flush() { fwrite(quq , 1 , O , stdout) ; fflush(stdout) ; O = 0 ; }
FILEOUT & operator << (char c) { return quq[O ++] = c , * this ; }
FILEOUT & operator << (string str) {
if(O > LIMIT) flush() ; for(char c : str) quq[O ++] = c ; return * this ;
}
Tp < class T > void write(T x) {
if(O > LIMIT) flush() ; if(x < 0) { quq[O ++] = 0x2d ; x = -x ; }
do { ST[++ sz] = x % 0xa ^ 0x30 ; x /= 0xa ; } while(x) ;
while(sz) quq[O ++] = ST[sz --] ; return ;
}
FILEOUT & operator << (int x) { return write(x) , * this ; }
FILEOUT & operator << (signed x) { return write(x) , * this ; }
FILEOUT & operator << (unsigned x) { return write(x) , * this ; }
} out ; const int maxn = 5e5 ;
int mu[maxn + 10] ;
const int mod = 998244353 ;
map < int , int > _mu ;
int getmu(int x) {
if(x <= maxn) return mu[x] ;
if(_mu[x]) return _mu[x] ;
int ans = 1 ;
int l = 2 , r = 0 ;
for( ; l <= x ; l = r + 1) {
r = x / (x / l) ;
ans -= getmu(x / l) * (r - l + 1) ;
ans = (ans + mod) % mod ;
}
return _mu[x] = ans ;
}
signed main() {
#ifdef _WIN64
freopen("testdata.in" , "r" , stdin) ;
#else
ios_base :: sync_with_stdio(false) ;
cin.tie(nullptr) , cout.tie(nullptr) ;
#endif
// code begin.
mu[1] = 1 ;
for(int i = 1 ; i <= maxn ; i ++)
for(int j = i + i ; j <= maxn ; j += i)
mu[j] -= mu[i] ;
for(int i = 2 ; i <= maxn ; i ++)
mu[i] = (mu[i] + mu[i - 1]) % mod ;
int n ;
in >> n ;
int l = 1 , r = 0 ;
int ans = 0 ;
for( ; l <= n ; l = r + 1) {
r = n / (n / l) ;
int qwq = (n / l) * (n / l) % mod * (n / l) % mod ;
ans = (ans + (getmu(r) - getmu(l - 1) + mod) % mod * qwq % mod) % mod ;
}
out << ans << '\n' ;
return out.flush() , 0 ;
// code end.
}

P6070 [RC-02] GCD [杜教筛,莫比乌斯反演]的更多相关文章

  1. BZOJ_4176_Lucas的数论_杜教筛+莫比乌斯反演

    BZOJ_4176_Lucas的数论_杜教筛+莫比乌斯反演 Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么喜欢了. 在整理以前的试题时,发现了这样一道题目“求 ...

  2. 【XSY2731】Div 数论 杜教筛 莫比乌斯反演

    题目大意 定义复数\(a+bi\)为整数\(k\)的约数,当且仅当\(a\)和\(b\)为整数且存在整数\(c\)和\(d\)满足\((a+bi)(c+di)=k\). 定义复数\(a+bi\)的实部 ...

  3. [CQOI2015][bzoj3930] 选数 [杜教筛+莫比乌斯反演]

    题面: 传送门 思路: 首先我们把区间缩小到$\left[\lfloor\frac{L-1}{K}\rfloor,\lfloor\frac{R}{K}\rfloor\right]$ 这道题的最特殊的点 ...

  4. [51Nod 1237] 最大公约数之和 (杜教筛+莫比乌斯反演)

    题目描述 求∑i=1n∑j=1n(i,j) mod (1e9+7)n<=1010\sum_{i=1}^n\sum_{j=1}^n(i,j)~mod~(1e9+7)\\n<=10^{10}i ...

  5. [bzoj 4176] Lucas的数论 (杜教筛 + 莫比乌斯反演)

    题面 设d(x)d(x)d(x)为xxx的约数个数,给定NNN,求 ∑i=1N∑j=1Nd(ij)\sum^{N}_{i=1}\sum^{N}_{j=1} d(ij)i=1∑N​j=1∑N​d(ij) ...

  6. bzoj 4916: 神犇和蒟蒻 (杜教筛+莫比乌斯反演)

    题目大意: 读入n. 第一行输出“1”(不带引号). 第二行输出$\sum_{i=1}^n i\phi(i)$. 题解: 所以说那个$\sum\mu$是在开玩笑么=.= 设$f(n)=n\phi(n) ...

  7. [51nod1220] 约数之和(杜教筛+莫比乌斯反演)

    题面 传送门 题解 嗯--还是懒得写了--这里 //minamoto #include<bits/stdc++.h> #define R register #define IT map&l ...

  8. LOJ 6229 LCM / GCD (杜教筛+Moebius)

    链接: https://loj.ac/problem/6229 题意: \[F(n)=\sum_{i=1}^n\sum_{j=1}^i\frac{\mathrm{lcm}(i,j)}{\mathrm{ ...

  9. 【BZOJ4176】Lucas的数论-杜教筛

    求$$\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}f(ij)$$,其中$f(x)$表示$x$的约数个数,$0\leq n\leq 10^9$,答案膜$10^9+ ...

随机推荐

  1. df du 文件空间管理 命令

     df  可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力. du 可以查看文件及文件夹的大小.     df:常用   df -h    以易读形式显示 磁盘空间 linux ...

  2. Vim 安装和配置、优化

    Vim 介绍 Vim 官网:http://www.vim.org/ Vim 安装 CentOS:sudo yum install -y vim Ubuntu:sudo apt-get install ...

  3. drf序列化大总结

    目录 一.APIView的请求生命周期 二.序列化组件 视图类中使用序列化 Meta配置类中的配置 自定义校验规则 入库方法 自定义字段 如果有群改操作 重(难)点 三.视图家族 四.路由组件 五.权 ...

  4. QT学习之路-QT服务器-mysql数据库相关问题集锦(1)

    时间:2017-04-07 异常信息: Error - RtlWerpReportException failed with status code :-1073741823. Will try to ...

  5. Linux运维---1.Ceph分布式存储架构及工作原理

    Ceph理论 Ceph 简介 Ceph 是一个开源项目,它提供软件定义的.统一的存储解决方案 .Ceph 是一个具有高性能.高度可伸缩性.可大规模扩展并且无单点故障的分布式存储系统 . Ceph 是软 ...

  6. Mybatis注解开发多表一对一,一对多

    Mybatis注解开发多表一对一,一对多 一对一 示例:帐户和用户的对应关系为,多个帐户对应一个用户,在实际开发中,查询一个帐户并同时查询该账户所属的用户信息,即立即加载且在mybatis中表现为一对 ...

  7. ViewPager调用notifyDataSetChanged() 刷新问题解决方案

    一.问题来由 ViewPager控件很大程度上满足了开发者开发页面左右移动切换的功能,使用非常方便.但是使用中发现,在删除或者修改数据的时候,PagerAdapter无法像BaseAdapter那样仅 ...

  8. centos7下查看mysql配置文件适用顺序

    mysql --help|grep 'my.cnf' [root@izm5e2q95pbpe1hh0kkwoiz ~]# mysql --help|grep 'my.cnf' order of pre ...

  9. Centos7之firewall配置命令

    firewalld的基本使用 查看状态:systemctl status firewalld 启动:systemctl start firewalld 停止:systemctl stop firewa ...

  10. Ubuntu安装C#语言开发环境

    使用Bash自动化安装 先下载Bash脚本(Linux/macOS),运行脚本 ./dotnet-install.sh -c Current 或者使用包管理器安装 wget -q https://pa ...