题目大意:
  给定$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. opencv中的仿射变换

    什么是仿射变换? 原理:1.一个任意的仿射变换都能表示为 乘以一个矩阵(线性变换) 接着再 加上一个向量(平移) 2.综上所述,我们能够用仿射变换来表示: 1)旋转(线性变换) 2)平移(向量加) 3 ...

  2. LoadRunner11的安装和使用及其注意点(测试系统是win7)

    一.安装 LoadRunner11的下载地址:http://www.ddooo.com/softdown/61971.htm 链接标题里[loadrunner11 中文破解版]实质上下载下来是没有破解 ...

  3. easyui-combogrid必填为空时无法通过表单验证的问题

    在使用easyui-combogrid时,由于html解析出的格式是如下三层: <td> <input id="txcombo" class="easy ...

  4. unknow table alarmtemp error when drop database (mysql)

    Q: unknow table alarmtemp error when  drop database (mysql) D: alarmtemp is table in rtmd database. ...

  5. 关于html头部引用(meta,link)

    /*这一段头部表示 如果安装了GCF,则使用GCF来渲染页面,如果为安装GCF,则使用最高版本的IE内核进行渲染.*/<meta content="IE=edge,chrome=1&q ...

  6. 【Best Time to Buy and Sell Stock】cpp

    题目: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...

  7. 【Gray Code】cpp

    题目: The gray code is a binary numeral system where two successive values differ in only one bit. Giv ...

  8. SpringCloud Eureka参数配置项详解

    SpringCloud Eureka参数配置项详解(转) Eureka涉及到的参数配置项数量众多,它的很多功能都是通过参数配置来实现的,了解这些参数的含义有助于我们更好的应用Eureka的各种功能,下 ...

  9. Spring AOP Example 文件下载:

      文件下载:http://files.cnblogs.com/wucg/spring_aop_excise.zip P:124 spring核心技术 P225: spring doc 可以把Advi ...

  10. 如何理解显示卡的驱动模块(DDX,DRM,DRI,XVMC)

    如何理解显示卡的驱动模块(DDX,DRM,DRI,XVMC) 1)DDX是什么 DDX是X服务器的2D驱动模块,例如via_drv.so. 2D的显示加速,包括xvideo也是由它负责. 它会初始化硬 ...