传送门

不会……

两篇加在一起都看不懂……

https://www.cnblogs.com/cellular-automaton/p/8241128.html

https://www.luogu.org/blog/cjyyb/solution-p3768

 //minamoto
#include<iostream>
#include<cstdio>
#include<map>
#define ll long long
using namespace std;
const int N=4e6+;
map<ll,ll> mp;
ll sum[N],phi[N],pri[N],cnt,vis[N],mod6,mod;
//mod是2的逆元,mod6是6的逆元
void init(ll p){
vis[]=sum[]=;
for(int i=;i<N;++i){
if(!vis[i]) pri[++cnt]=i,phi[i]=i-,sum[i]=1ll*i*i%p*phi[i]%p;
for(int j=;j<=cnt,i*pri[j]<N;++j){
vis[i*pri[j]]=;
int now=i*pri[j];
if(i%pri[j]==){
phi[now]=phi[i]*pri[j]%p;
sum[now]=phi[now]*now%p*now%p;
break;
}
phi[now]=phi[i]*(pri[j]-)%p;
sum[now]=phi[now]*now%p*now%p;
}
}
for(int i=;i<N;++i) (sum[i]+=sum[i-])%=p;
}
ll ksm(ll x,ll y,ll p){
ll res=;
while(y){
if(y&) (res*=x)%=p;
(x*=x)%=p,y>>=;
}
return res;
}
ll calc(ll n,ll p){
n%=p;
ll res=((+n)*n%p)*mod%p;
(res*=res)%=p;
return res;
}
ll calcs(ll n,ll p){
n%=p;
ll res=(n*(n+)%p)*(*n+)%p;
(res*=mod6)%=p;
return res;
}
ll calcsum(ll n,ll p){
if(n<N) return sum[n];
if(mp.count(n)) return mp[n];
ll x=,res=calc(n,p);
while(x<=n){
ll y=n/(n/x);
res=((res-(calcs(y,p)-calcs(x-,p)+p)%p*calcsum(n/x,p)%p)+p)%p;
x=y+;
}
return mp[n]=res;
}
int main(){
// freopen("testdata.in","r",stdin);
ll p,n;
scanf("%lld%lld",&p,&n);
mod=ksm(,p-,p),mod6=ksm(,p-,p);
init(p);
ll x=,ans=;
while(x<=n){
ll y=n/(n/x);
(ans+=((calcsum(y,p)-calcsum(x-,p)+p)%p*calc(n/x,p)%p))%=p;
x=y+;
}
printf("%lld\n",ans);
return ;
}

洛谷P3768 简单的数学题(莫比乌斯反演+狄利克雷卷积+杜教筛)的更多相关文章

  1. 洛谷P3768 简单的数学题 莫比乌斯反演+杜教筛

    题意简述 求出这个式子 \[ \sum_{i=1}^n\sum_{j=1}^n ij(i,j) \bmod p \] 做法 先用莫比乌斯反演拆一下式子 \[ \begin{split} \sum_{i ...

  2. 中国剩余定理 & 欧拉函数 & 莫比乌斯反演 & 狄利克雷卷积 & 杜教筛

    ssplaysecond的博客(请使用VPN访问): 中国剩余定理: https://ssplaysecond.blogspot.jp/2017/04/blog-post_6.html 欧拉函数: h ...

  3. 【刷题】洛谷 P3768 简单的数学题

    题目描述 由于出题人懒得写背景了,题目还是简单一点好. 输入一个整数n和一个整数p,你需要求出(\(\sum_{i=1}^n\sum_{j=1}^n ijgcd(i,j))~mod~p\),其中gcd ...

  4. 洛谷 - P3768 - 简单的数学题 - 欧拉函数 - 莫比乌斯反演

    https://www.luogu.org/problemnew/show/P3768 \(F(n)=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}ijgcd(i ...

  5. 洛谷 P3768 简单的数学题 解题报告

    P3768 简单的数学题 题目描述 由于出题人懒得写背景了,题目还是简单一点好. 输入一个整数\(n\)和一个整数\(p,\)你需要求出\((\sum_{i=1}^n\sum_{j=1}^n ijgc ...

  6. 洛谷P3768 简单的数学题

    解: 神奇的一批......参观yyb巨神的博客. 大致思路就是第一步枚举gcd,发现后面有个限制是gcd=1,用反演,得到的F(x)是两个等差数列求积. 然后发现有个地方我们除法的除数是乘积,于是换 ...

  7. 洛谷 P3768 简单的数学题

    https://www.luogu.org/problemnew/show/P3768 化简一下式子,就是$\sum_{d=1}^ncalc(d)d^2\varphi(d)$ 其中$calc(d)=\ ...

  8. 洛谷P3768 简单的数学题 【莫比乌斯反演 + 杜教筛】

    题目描述 求 \[\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{n} i*j*gcd(i,j) \pmod{p}\] \(n<=10^{10}\),\(p\) ...

  9. 洛谷 P3768 简单的数学题 (莫比乌斯反演)

    题意:求$(\sum_{i=1}^{n}\sum_{j=1}^{n}ijgcd(i,j))mod p$(p为质数,n<=1e10) 很显然,推式子. $\sum_{i=1}^{n}\sum_{j ...

随机推荐

  1. BZOJ 3671 NOI2014 随机数生成器

    这题其实是个暴力. 首先那一堆如何构造n*m方格的东西都是在玩你. 构造出来方阵后,由于是一个排列,不存在重复,可以大力贪心. 每次将选出一个最小的元素,然后将它右上左下的元素全部打上标记(记得bre ...

  2. 51nod 1022 石子归并 V2 —— DP四边形不等式优化

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1022 1022 石子归并 V2  基准时间限制:1 秒 空间限 ...

  3. Contiki 2.7 Makefile 文件(二)

    二.Makefile.include 1.第一部分 (1) ifndef CONTIKI ${error CONTIKI not defined! You must specify where Con ...

  4. 基于对话框的Opengl框架

    转自:http://blog.csdn.net/longxiaoshi/article/details/8238933 12-11-29 14:55 1198人阅读 评论(6) 收藏 举报  分类: ...

  5. Oracle约束的使用

    --5个约束,主键约束.外键约束.唯一约束.检查约束.非空约束. --添加主键约束 Alter table table_name Add constraints constraint_name Pri ...

  6. python做简易记事本

    以下内容参考<辛星tkinter教程第二版>: from tkinter import * from tkinter.filedialog import * from tkinter.me ...

  7. the art of seo(chapter eleven)

    Tracking Results and Measuring Success goal -> driver ***Why Measuring Success Is Essential to th ...

  8. 前端多媒体(4)—— video标签全面分析

    测试地址:https://young-cowboy.github.io/gallery/html5_video/index.html 属性 一些属性是只读的,一些属性是可以修改从而影响视频播放的. a ...

  9. android自定义控件(四) View中的方法

    onFinishInflate() 当View中所有的子控件 均被映射成xml后触发 onMeasure(int, int) 确定所有子元素的大小 onLayout(boolean, int, int ...

  10. OpenCV——旋转模糊

    参考来源: 学习OpenCV:滤镜系列(5)--径向模糊:缩放&旋转 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #defi ...