P6070 [RC-02] GCD [杜教筛,莫比乌斯反演]
没啥好说的,杜教筛板子题。
\]
容易发现,我们枚举 \(j\) 其实是相当于枚举 \(\gcd\)
才不是枚举题目
然后式子可以变成
\]
然后套路式的枚举 \(gcd\) 依旧不是枚举题目
\]
熟悉的形式,其实就等于
\]
\]
然后整除分块就完了,由于 \(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 [杜教筛,莫比乌斯反演]的更多相关文章
- BZOJ_4176_Lucas的数论_杜教筛+莫比乌斯反演
BZOJ_4176_Lucas的数论_杜教筛+莫比乌斯反演 Description 去年的Lucas非常喜欢数论题,但是一年以后的Lucas却不那么喜欢了. 在整理以前的试题时,发现了这样一道题目“求 ...
- 【XSY2731】Div 数论 杜教筛 莫比乌斯反演
题目大意 定义复数\(a+bi\)为整数\(k\)的约数,当且仅当\(a\)和\(b\)为整数且存在整数\(c\)和\(d\)满足\((a+bi)(c+di)=k\). 定义复数\(a+bi\)的实部 ...
- [CQOI2015][bzoj3930] 选数 [杜教筛+莫比乌斯反演]
题面: 传送门 思路: 首先我们把区间缩小到$\left[\lfloor\frac{L-1}{K}\rfloor,\lfloor\frac{R}{K}\rfloor\right]$ 这道题的最特殊的点 ...
- [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 ...
- [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∑Nj=1∑Nd(ij) ...
- bzoj 4916: 神犇和蒟蒻 (杜教筛+莫比乌斯反演)
题目大意: 读入n. 第一行输出“1”(不带引号). 第二行输出$\sum_{i=1}^n i\phi(i)$. 题解: 所以说那个$\sum\mu$是在开玩笑么=.= 设$f(n)=n\phi(n) ...
- [51nod1220] 约数之和(杜教筛+莫比乌斯反演)
题面 传送门 题解 嗯--还是懒得写了--这里 //minamoto #include<bits/stdc++.h> #define R register #define IT map&l ...
- 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{ ...
- 【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+ ...
随机推荐
- DG参数 LOG_ARCHIVE_DEST_n
DG参数 LOG_ARCHIVE_DEST_n This chapter provides reference information for the attributes of the LOG_AR ...
- java架构之路-(微服务专题)初步认识微服务与nacos初步搭建
历史演变: 以前我们都是一个war包,包含了很多很多的代码,反正我开始工作的时候做的就是这样的项目,一个金融系统,代码具体多少行记不清楚了,内部功能超多,但是实际能用到的不多,代码冗余超大,每次部署大 ...
- [Effective Java 读书笔记] 第8章 通用程序设计
本章主要讲了以下几条基本的JAVA编程原则: 1.将局部变量的作用域控制在最小,在使用时才定义 2.for-each优于for循环 有三个例外(1,2点主旨就是,for each只能用于读取,不能用于 ...
- chromedriver和firefox driver的安装过程
环境:ubuntu14.04, python2.7 selenium2.0 文章参考出处:http://blog.csdn.net/heybob/article/details/52922645 ch ...
- vue 的点击事件怎么获取当前点击的元素
手机赚钱怎么赚,给大家推荐一个手机赚钱APP汇总平台:手指乐(http://www.szhile.com/),辛苦搬砖之余用闲余时间动动手指,就可以日赚数百元 首先 vue的点击事件 是用 @cl ...
- CSS选择器有哪些?选择器的优先级如何排序?
CSS选择器分类: CSS的选择器分类可以分为三大类:id选择器,类选择器,标签选择器. 用法如下: 选择器 e.g. 说明 id选择器 #id #header 选择id="header ...
- Python——模块和包
一.概念 """模块():一个python文件,以 .py 结尾,包含python对象定义和语句.模块可以定义函数.类.变量,也可包含可执行文件 导入模块: 1.impo ...
- Vue整合d3.v5.js制作--柱状图(rect)
先上效果图: 图中柱状图变成纯蓝色是鼠标滑动过的颜色(颜色可改,本人配色能力十分的强,建议直接用默认设置即可 ( ᖛ ̫ ᖛ )ʃ)) 1.环境说明 Vue版本:"vue": &q ...
- clr via c# 接口
1,常用接口及其定义 public interface IDisposable{ void Dispose(); } public interface IEnumerable}{ IEnumerato ...
- C#设计模式学习笔记:(5)原型模式
本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/7640873.html,记录一下学习过程以备后续查用. 一.引言 很多人说原型设计模式会节省机器内存,他们说 ...