[51nod1238] 最小公倍数之和 V3(杜教筛)
题面
题解
懒了……这里写得挺好的……
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define IT map<ll,int>::iterator
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
const int N=6e6+5,P=1e9+7,inv2=500000004,inv6=166666668;
bitset<N>vis;int p[N],phi[N],g[N],m,sqr;ll n;map<ll,int>mp;
inline int calc(R int x){return (1ll*x*(x+1)>>1)%P;}
inline int calc2(R int x){return 1ll*x*(x+1)%P*((x<<1)+1)%P*inv6%P;}
inline int calc3(R int x){x=calc(x);return 1ll*x*x%P;}
void init(int n){
phi[1]=g[1]=1;
fp(i,2,n){
if(!vis[i])p[++m]=i,phi[i]=i-1,g[i]=1ll*phi[i]*i%P*i%P;
for(R int j=1,k;j<=m&&1ll*i*p[j]<=n;++j){
vis[k=i*p[j]]=1;
if(i%p[j]==0){phi[k]=phi[i]*p[j],g[k]=1ll*phi[k]*k%P*k%P;break;}
phi[k]=phi[i]*(p[j]-1),g[k]=1ll*g[i]*g[p[j]]%P;
}
}
fp(i,2,n)(g[i]+=g[i-1])%=P;
}
int G(ll n){
if(n<=sqr)return g[n];
IT it=mp.find(n);
if(it!=mp.end())return it->second;
int res=calc3(n%P),las=1,now;
for(ll i=2,j;i<=n;i=j+1)
j=n/(n/i),now=calc2(j%P),res=(res-1ll*(now-las+P)*G(n/i)%P+P)%P,las=now;
return mp[n]=res;
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%lld",&n),init(sqr=N-5);
int res=0,las=0,now=0;
for(R ll i=1,j;i<=n;i=j+1)
j=n/(n/i),now=calc(j%P),(res+=1ll*(now-las+P)*G(n/i)%P)%=P,las=now;
printf("%d\n",res);
return 0;
}
[51nod1238] 最小公倍数之和 V3(杜教筛)的更多相关文章
- [51Nod1238]最小公倍数之和 V3[杜教筛]
题意 给定 \(n\) ,求 \(\sum_{i=1}^n \sum_{j=1}^n lcm(i,j)\). \(n\leq 10^{10}\) 分析 推式子 \[\begin{aligned} an ...
- 51NOD 1238 最小公倍数之和 V3 [杜教筛]
1238 最小公倍数之和 V3 三种做法!!! 见学习笔记,这里只贴代码 #include <iostream> #include <cstdio> #include < ...
- 【51nod】1238 最小公倍数之和 V3 杜教筛
[题意]给定n,求Σi=1~nΣj=1~n lcm(i,j),n<=10^10. [算法]杜教筛 [题解]就因为写了这个非常规写法,我折腾了3天…… $$ans=\sum_{i=1}^{n}\s ...
- 51 Nod 1238 最小公倍数之和 V3 杜教筛
题目链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题意:求$\sum_{i=1}^{n}\sum_{j=1}^{n}l ...
- 51NOD 1237 最大公约数之和 V3 [杜教筛]
1237 最大公约数之和 V3 题意:求\(\sum_{i=1}^n\sum_{j=1}^n(i,j)\) 令\(A(n)=\sum_{i=1}^n(n,i) = \sum_{d\mid n}d \c ...
- [51Nod 1238] 最小公倍数之和 (恶心杜教筛)
题目描述 求∑i=1N∑j=1Nlcm(i,j)\sum_{i=1}^N\sum_{j=1}^Nlcm(i,j)i=1∑Nj=1∑Nlcm(i,j) 2<=N<=10102<=N ...
- 51nod 237 最大公约数之和 V3 杜教筛
Code: #include <bits/stdc++.h> #include <tr1/unordered_map> #define setIO(s) freopen(s&q ...
- 51nod1238 最小公倍数之和 V3 莫比乌斯函数 杜教筛
题意:求\(\sum_{i = 1}^{n}\sum_{j = 1}^{n}lcm(i, j)\). 题解:虽然网上很多题解说用mu卡不过去,,,不过试了一下貌似时间还挺充足的,..也许有时间用phi ...
- 51nod 1244 莫比乌斯函数之和 【杜教筛】
51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...
- 51nod 1244 莫比乌斯函数之和(杜教筛)
[题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...
随机推荐
- java.lang.Runtime.exec() Payload Workarounds
由于Runtime.getRuntime().exec()中不能使用管道符等bash需要的方法,我们需要用进行一次编码 编码工具: 地址: http://jackson.thuraisamy.me/r ...
- mysql 回顾小练习
Student(id,sname,age,sex) 学生表 Course(id,cname,t_id) 课程表 SC(s_id,c_id,score) 成绩表 Teacher(id,Tname) 教师 ...
- 11-24网页基础--Js基础语法
1.运算符 比较运算符(7种):==/===/!=/>/</<=/>= ===(全等于) 2.字符串substring的用法 3.练习题:累加求和(运用Js的方法) 4.进制转 ...
- ajax跨域请求-jsonp
1. 同源策略 ajax之所以需要“跨域”,罪魁祸首就是浏览器的同源策略.即,一个页面的ajax只能获取这个页面相同源或者相同域的数据. 如何叫“同源”或者“同域”呢?——协议.域名.端口号都必须相同 ...
- struts2学习笔记(4)接收参数
①用action属性接收 登录界面例子 在webroot下创建login.jsp和success.jsp login.jsp中加入表单: <form action="LoginActi ...
- windows下单机版的伪分布式solrCloud环境搭建Tomcat+solr+zookeeper
原文出自:http://sbp810050504.blog.51cto.com/2799422/1408322 按照该方法,伪分布式solr部署成功 ...
- Absolute Layout
----------------siwuxie095 根面板 contentPane 的默认布局为 Border Layout,将其 切换为 Absolute Layout Absolute Layo ...
- Vue02 样式的动态绑定
daigengxin......2018-3-8 21:09:18 跟angular2类似,分为CSS类绑定和Style样式绑定两种方式,详情参见
- Python 网络爬虫 007 (编程) 通过网站地图爬取目标站点的所有网页
通过网站地图爬取目标站点的所有网页 使用的系统:Windows 10 64位 Python 语言版本:Python 2.7.10 V 使用的编程 Python 的集成开发环境:PyCharm 2016 ...
- Zbar 大图像分析
博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50429252 为了减少处理时间,可以设定更大的扫描间距,减少不必要的解码类型,去 ...