题目大意:
  给定$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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Divisors

    计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...

  4. Xenia and Divisors

    Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...

  6. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  7. Sum of divisors

    Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...

  8. 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 ...

  9. UVa 294 (因数的个数) Divisors

    题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...

随机推荐

  1. 基础_String

    String str1="hello"; String str2="hello"; String str3="hello"; String ...

  2. IOS开发学习笔记034-UIScrollView-xib实现分页

    通过xib实现分页功能的封装 1.首先实现xib UIView 的尺寸为300*130,因为准备的图片为600*260. scrollView属性设置如下: 2.新建一个和xib同名的类 2.1 类方 ...

  3. sqlserver 操作access数据库

    exec sp_configure 'show advanced options',1  reconfigure  exec sp_configure 'Ad Hoc Distributed Quer ...

  4. python 中输入一个字符串,判断这个字符串中有多少个字符、数字、空格、特殊字符

    # -*- coding: utf8 -*- # Author:wxq #python 2.7 #首先定义一个字符串 str1 = raw_input('请输入一个字符:') #初始化字符.数字.空格 ...

  5. docker exec小脚本

    经常要使用docker exec -it containerID bash 进入docker内部进行一些操作,干脆把它写成shell脚本节省时间. # 查看需要操作的容器id $ docker ps ...

  6. hibernate注解配置举例说明

    Hibernate Annotation   (Hibernate 注解)   进入:http://www.hibernate.org 说明文档: 英文:http://docs.jboss.org/h ...

  7. 【转】Unity3d的单例及场景间的数据传递

    http://blog.csdn.net/zy19940906/article/details/47724387  单例是场景间切换时传递数据的最常见的方式之一,在unity中,很多方法被封装,有时候 ...

  8. 【bzoj2527】[Poi2011]Meteors 整体二分+树状数组

    题目描述 有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站. 这个星球经常会下陨石雨.BIU已经预测了接下来K场陨石雨的情况.BI ...

  9. JavaScript内存分配

    1.栈内存和堆内存 栈内存为自动分配的内存空间,由系统自动释放堆内存是动态分配的内存,大小不固定,也不会自动释放 js的值类型直接分配在栈内存中,引用类型分配在堆内存中引用类型变量保存的是引用类型的指 ...

  10. vue使用stylus

    在package.json中添加  stylus-loader "css-loader": "^0.28.0", "stylus-loader&quo ...