[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> ...
随机推荐
- 使用Vue CLI3开发多页面应用
一.安装vue-cli3 1.如果你已经全局安装了旧版本的 vue-cli(1.x 或 2.x),你需要先通过 npm uninstall vue-cli -g 或 yarn global remov ...
- Cakephp在Controller中显示sql语句
Cakephp在Controller中查询语句一般是: $this->Model->find(); 那么这条语句对应的sql语句是什么呢? 可以通过下面方法显示: 1. $dbo = Co ...
- ffmpeg转换参数和对几种视频格式的转换分析
我们在将多种格式的视频转换成flv格式的时候,我们关注的就是转换后的flv视频的品质和大小.下面就自己的实践所得来和大家分享一下,主要针对avi.3gp.mp4和wmv四种格式来进行分析.通常在使用f ...
- IOS开发---菜鸟学习之路--(二)-数据获取
第二篇了. 本篇要讲的是数据获取. 为什么将数据获取放在第二篇就讲呢? 因为我在看别人教程的时候都是先讲控件的属性,然后怎么用控件开始. 可是毕竟咱们也是有一定开发经验的人..所以很自然就想先知道怎么 ...
- 【Word Ladder II】cpp
题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...
- leetcode 【 Set Matrix Zeroes 】python 实现
题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. cl ...
- Python-S9-Day89_stark总结
01 Stark总结 02 ORM总结 03 上节作业 04 Stark组件之查看页面表头 05 list_display_links 06 stark组件之添加页面 07 编辑删除页面 01 Sta ...
- python实现删除空文件夹 附源代码
前言:空文件夹虽然不占空间,但是有时候看着确实挺烦的(别误会,我不是强迫症!),所以写了一个用于删除当前目录下的空文件夹的小程序 环境:win7 64位:python2.7:IDE pycharm20 ...
- PAT——乙级1026and1046
1026 程序运行时间 (15 point(s)) 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() ...
- 整理 pycharm console调试博客
在Debug模式下,查看变量发现只能看到300个变量,报错: two large to show contents. Max items to show:300. 点击Debugger左侧consol ...