[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 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...
随机推荐
- Nunit 2.6 无法调试.Net Framework 4.0
<configuration> <!-- The GUI only runs under .NET 2.0 or higher. The useLegacyV2RuntimeActi ...
- java代码split分割数字类
总结:正则表达式-- package com.c2; //写一个spli的用法,数字类 ===分割字符串 public class yqw { public static void main(Stri ...
- 2018年长沙理工大学第十三届程序设计竞赛 H数学考试
链接:https://www.nowcoder.com/acm/contest/96/H来源:牛客网 数学考试 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- Redis 复制技术和高可用sentinel(哨兵模式)
redis的复制技术和高可用(哨兵模式) 1 复制 为什么要复制 实现数据的多副本存储,从而可以实现服务的高可用 提供更好的读性能复制技术的关键点及难点 如何指定被复制对象 增量还是全量以及如何实现增 ...
- docker 笔记(6)网络
docker network ls 默认docker安装时会创建3个网络 none网络 one 网络就是什么都没有的网络.挂在这个网络下的容器除了 lo,没有其他任何网卡.容器创建时,可以通过 - ...
- LAMP 3.2 mysql登陆
mysql 服务启动时,不仅会监听 IP:Port,还会监听一个 socket,我们安装的 mysql 是监听在/tmp/mysql.sock.如果 php 是在本地,那么 php 和 mysql 通 ...
- Niginx +Tomcat 集群搭建
1 安装niginx服务器,然后启动,访问localhost;出现欢迎界面证明niginx启动成功: 如上图的目录是nginx1.1的目录结构: 2 之后下载tomcat,然后赋值一份,总共两个tom ...
- jquery获取元素在文档中的位置信息以及滚动条位置(转)
jquery获取元素在文档中的位置信息以及滚动条位置 http://blog.csdn.net/qq_34095777/article/details/78750886 原文链接 原创 201 ...
- C++面向对象类的实例题目三
编写一个程序,设计一个满足如下要求的CData类. (1)用下面的格式输出日期:日/月/年 (2)输出在当前日期上加一天后的日期 (3)设置日期 code: #include<iostream& ...
- java中字符串处理、串联和转换的几个常用方法,以及如果需要自己编程实现的具体实施步骤。
What? 如何分类? 如何使用? //String 类提供处理 Unicode 代码点(即字符)(TT观点:指的莫非就是对象的意思.)和 Unicode 代码单元(即 char 值)的方法.(TT观 ...