膜拜 rqy。

题意:

求:

\[\sum_{i=1}^n \sigma_0(i^2)
\]

首先我们知道 \(\sigma_0((p^k)^2)=2 \times k + 1=k+(k+1)=\sigma_0(p^k)+\sigma_0(p^{k-1})=(\mu^2 * \sigma_0)(p^k)\)

那么我们大力展开:

\[\sum_{i=1}^n\sum_{d|i}\mu^2(d) \times \sigma_0(\frac n d)
\]
\[\sum_{d=1}^n \mu^2(d)\sum_{i=1}^{\lfloor \frac n d \rfloor}\sigma_0(\frac n d)
\]

众所周知 \(\sum_{i=1}^n \sigma_0(i)=\sum_{i=1}^n \lfloor \frac n i \rfloor,\sum_{i=1}^n\mu^2(i)=\sum_{i=1}^{\sqrt n}\mu(i)\lfloor \frac n {i^2} \rfloor\),那么这里再使用杜教筛的数据分治即可做到 \(O(n^{\frac 2 3}+Tn^{\frac 2 3})\)。

稍微卡下常数就能 11.53s 了。实际上容易发现瓶颈其实是线性筛。。。

#include<unordered_map>
#include<cstdio>
#include<bitset>
#include<cmath>
typedef unsigned ui;
typedef __uint128_t L;
typedef unsigned long long ull;
const ui M=1e8+5;
ui T,lim,d[M],s[M];ui top,pri[5761456];ull n[10005];std::bitset<M>vis,mu1,mu2;
std::unordered_map<ull,ull>s1,d1;
struct FastDiv{
ull b,m;
FastDiv(const ull&x=1):b(x),m(ull((L(1)<<64)/x)){}
friend inline ull operator/(const ull&a,const FastDiv&mod){
if(mod.b==1)return a;ull r=1+(L(mod.m)*a>>64);return r-(a-r*mod.b>>63);
}
}F[1000005],G[1000005];
inline void sieve(const ui&n){
ui i,j,x;d[1]=1;vis[1]=1;mu1[1]=1;
for(i=1;i<=1000001;++i)F[i]=FastDiv(i),G[i]=FastDiv(1ull*i*i);
for(i=2;i<=n;++i){
if(!vis[i])mu2[pri[++top]=i]=true,d[i]=s[i]=2;
for(j=1;j<=top&&(x=i*pri[j])<=n;++j){
if(vis[x]=true,!(i%pri[j])){
d[x]=ui(d[i]/F[s[i]])*(s[x]=s[i]+1);break;
}
d[x]=d[i]<<1;s[x]=2;(mu1[i]||mu2[i])&&(mu1[x]=mu1[i]^1,mu2[x]=mu2[i]^1);
}
}
for(i=1;i<=n;++i)s[i]=mu1[i]||mu2[i],s[i]+=s[i-1],d[i]+=d[i-1];
}
inline ull S(const ull&n){
if(n<lim)return d[n];if(d1.find(n)!=d1.end())return d1[n];
ui i;ull ans(0);for(i=1;1ull*i*i<=n;++i)ans+=n/F[i];return--i,d1[n]=(ans<<1)-1ull*i*i;
}
inline ull Sum(const ull&n){
if(n<lim)return s[n];if(s1.find(n)!=s1.end())return s1[n];ui i;ull ans(0);
for(i=1;1ull*i*i<=n;++i)mu1[i]&&(ans+=n/G[i]),mu2[i]&&(ans-=n/G[i]);return s1[n]=ans;
}
inline ull Solve(const ull&n){
ull L,R,ans(0);ui x;
for(L=1;1ull*lim*L<=n;++L)if(mu1[L]||mu2[L])ans+=S(n/F[L]);
for(;1ull*L*L<=n;++L)if(mu1[L]||mu2[L])ans+=d[n/F[L]];
for(x=n/F[L];L<=n;L=R+1)1ull*x*L>n&&--x,ans+=d[x]*(Sum(R=n/F[x])-Sum(L-1));
return ans;
}
signed main(){
ull mx(0);scanf("%u",&T);for(ui i=1;i<=T;++i)scanf("%llu",n+i),n[i]>mx&&(mx=n[i]);sieve(lim=pow(mx,2./3));
for(ui i=1;i<=T;++i)printf("%llu\n",Solve(n[i]));
}

SP20173题解的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  8. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  9. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. Java高级特性——反射

    感谢原文作者:peter_RD_nj 原文链接:https://www.jianshu.com/p/9be58ee20dee 注意:同一个类在JVM中只存在一份字节码对象 概述 定义 JAVA反射机制 ...

  2. hibernate中的一级缓存与闪照区

    首先Hibernate中的一级缓存默认是打开的,并且范围从session创建到session关闭,存储的数据必须是持久态的数据. 1 //从session创建开始,一级缓存也跟着创建 2 Sessio ...

  3. hibernate中的映射文件xxx.hbm.xml详解总结

    转自 http://blog.csdn.net/a9529lty/article/details/6454924 一.hibernate映射文件的作用: Hibernate映射文件是Hibernate ...

  4. java中将SimpleDateFormat类型转换成Date类型

    try {String dateString = "2009-08-02 13:43:00";DateFormat df = SimpleDateFormat("yyyy ...

  5. Python篇函数总结【输出函数】

    1.raw_input("\n\nPress the enter key to exit.") 以上代码中 ,"\n\n"在结果输出前会输出两个新的空行.一旦用 ...

  6. Lesson14——NumPy 字符串函数之 Par3:字符串信息函数

    NumPy 教程目录 1 字符串信息函数 1.1 numpy.char.count char.count(a, sub, start=0, end=None) 返回一个数组,其中包含 [start, ...

  7. KiSystemCall64 win10 21h2函数流程分析 3环到0环

    0x00基本信息 系统:windows 10 21h2 工具:ida 7.7 , windbg 10 3环写一个win32k 函数 看访问流程 0x01分析 例如:3环函数 FlattenPath(x ...

  8. Solution -「AGC 002F」「AT 2000」Leftmost Ball

    \(\mathcal{Description}\)   Link.   给你 \(n\) 种颜色的球,每个球有 \(k\) 个,把这 \(n\times k\) 个球排成一排,把每一种颜色的最左边出现 ...

  9. [LeetCode]14.最长公共前缀(Java)

    原题地址: longest-common-prefix 题目描述: 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入:st ...

  10. linux 利用python模块实现格式化json

    非json格式示例 {"name": "chen2ha", "where": {"country": "Chi ...