[CF665F]Four Divisors
题目大意:
给定$n(n\leq10^{11})$,求$\displaystyle\sum_{i=1}^n[\tau(i)=4]$。
思路:
设$p,q$为不相等的质数,则满足$\tau(i)=4$的数$i$一定可以表示成$pq$或$p^3$。
对于$i=pq$的情况,可以先线性筛预处理出$\sqrt n$以内的质数,然后用LOJ6235的方法,用洲阁筛求出DP数组$f$。加上$last[j]-1$就是当$p_i^2>j$时不用$-1$转移,也就是加上了$p_i^2>j$的质数个数。此时$f[cnt+1-p_i]$表示的就是$\pi(n/p_i)-\pi(\sqrt n)$。统计答案时,枚举素数$p_i$,求$\sum_{p_i\leq\sqrt n}(\pi(n/p_i)-\pi(p_i))$即可。
对于$i=p^3$的情况,直接在筛出来的质数中二分答案即可。
时间复杂度$O\left(\frac{n^{\frac34}}{\ln n}\right)$。
细节:
$n=1$时二分会挂掉,需要特判。
#include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<functional>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int LIM=,P=;
bool vis[LIM];
int lim,p[P],sum[LIM],last[LIM*],cnt;
int64 n,val[LIM*],f[LIM*];
inline void sieve() {
for(register int i=;i<=lim;i++) {
if(!vis[i]) p[++p[]]=i;
sum[i]=sum[i-]+!vis[i];
for(register int j=;j<=p[]&&i*p[j]<=lim;j++) {
vis[i*p[j]]=true;
if(i%p[j]==) break;
}
}
}
int main() {
lim=sqrt(n=getint());
sieve();
for(register int64 i=;i<=n;i=n/(n/i)+) {
val[++cnt]=n/i;
}
std::reverse(&val[],&val[cnt]+);
std::copy(&val[],&val[cnt+],&f[]);
for(register int i=;i<=p[];i++) {
for(register int j=cnt;j;j--) {
const int64 k=val[j]/p[i],pos=k<=lim?k:cnt+-n/k;
if(k<p[i]) break;
f[j]-=f[pos]+last[pos]-i+;
last[j]=i;
}
}
int64 ans=;
for(register int i=;i<=cnt;i++) {
f[i]+=last[i]-;
}
for(register int i=;i<=p[];i++) {
ans+=f[cnt+-p[i]]-i;
}
if(n!=) ans+=std::upper_bound(&p[],&p[p[]]+,floor(pow(n,./)))-&p[];
printf("%lld\n",ans);
return ;
}
[CF665F]Four Divisors的更多相关文章
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- UVa 294 (因数的个数) Divisors
题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...
随机推荐
- BZOJ 1531: [POI2005]Bank notes
按余数分类 单调队列优化 #include<cstdio> using namespace std; int n,m,b[205],c[205],F[20005]; struct node ...
- 组装需要的json数据格式
在实际项目中有时候会遇到一些有特殊要求的控件,比如easyui-combogrid,加载的并不是常见的json格式,这里我遇到过需要加载类似省市县这种三级数据格式.最后也是从别人的博客中学到的如何组装 ...
- 转载: CRichEditCtrl使用大全
richedit 常见使用问题 一.常见问题 a.可以编译,不能执行的 在需要在相应的对话框中加上InitInstance(void)函数中添加 AfxInitRichEdit(); b.升级默认的R ...
- Python+Selenium练习篇之1-摘取网页上全部邮箱
前面已经介绍了Python+Selenium基础篇,通过前面几篇文章的介绍和练习,Selenium+Python的webUI自动化测试算是入门了.接下来,我计划写第二个系列:练习篇,通过一些练习,了解 ...
- LeetCode——Problem3:Longest Substring Without Repeating Characters
哎哟我天啊.这道题快折磨死我了.刚开始连题都没看明白,就是不知道substring是什么意思.研究了好长时间才看出来的. 光辉历史呀...菜死了 1.题目 Given a string, find t ...
- Summary—【base】(HTML)
Html知识点: 1. 建议开发人员计算机基本配置 a) 显示所有文件的后缀名* b) 文件的排列方式改为详细信息,并且名称一定要能够全部显示出来 c) 使用小的任务栏 d) 将常用的工具锁定到任务栏 ...
- JVM(8):JVM知识点总览-高级Java工程师面试必备
http://www.importnew.com/23792.html jvm 总体梳理 jvm体系总体分四大块: 类的加载机制 jvm内存结构 GC算法 垃圾回收 GC分析 命令调优 当然这些知识点 ...
- 【bzoj2083】[Poi2010]Intelligence test STL-vector+二分查找
题目描述 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练习,所 ...
- 并查集:按秩合并 $n$ 个点所得树高不超过 $\lfloor\log n \rfloor$
用 $h_n$ 表示按秩合并 $n$ 个点所得树的最大高度. 有 $h_1 = 0, h_2 = 1, h_3 = 1, h_4 = 2, h_5 = 2, \dots$ 有如下地推: \[ h_n ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...