二维rmq 离线 init O( n*n*logn*logn )  query O(1)

http://www.cnblogs.com/kuangbin/p/3227420.html

求1-n有多少个素数 n = 1e9

 #include <bits/stdc++.h>
using namespace std;
namespace acm {
/// count primes between [1..n] (0< n <=1e9)
/// solution: dp
/// d(n, i) means that the number of value whose min prime number is bigger than i in [1..n]
/// d(n, i) = d(n, i-1) if number i is not a prime
/// d(n, i) = d(n, i-1) - d(n/i, i) + d(i, i-1) if number i is a prime
/// complex time: O(n^(3/4)), space: O(n^(1/2))
struct CountPrime {
int solve(int n) {
if (n < ) {
return ;
}
dp[] = ;
int sqrtn = , length = ;
for (; sqrtn <= n / sqrtn; ++sqrtn) {
dp[++length] = sqrtn - ;
}
for (int i = sqrtn - ; i > ; --i) {
int val = n / i;
if (val != i) {
dp[++length] = val - ;
}
}
for (int i = ; i < sqrtn; ++i) {
if (dp[i] == dp[i-]) {
continue;
}
for (int j=length; j>; --j) {
int val = j < sqrtn ? j : n / (length - j + );
if (i > val / i) {
break;
}
int pre_statue_pos = val / i;
if (pre_statue_pos >= sqrtn) {
pre_statue_pos = length - n / pre_statue_pos + ;
}
dp[j] += dp[i-] - dp[pre_statue_pos];
}
}
return dp[length];
}
static const int maxn = 1e5+;
int dp[maxn];
};
} // namespace acm
int main()
{
//freopen("dp.in", "r", stdin);
//freopen("dp.out", "w", stdout);
acm::CountPrime cp;
int n;
while (scanf ("%d", &n) != EOF) {
printf ("%d\n", cp.solve(n));
}
return ;
}

end

add some template for ec-final的更多相关文章

  1. [MODx] 1. Add Html5 template into the MODx

    1. Connet MODx by SSH: Go to the MODx cloud; Find you current user and right click selet Edit Cloud; ...

  2. DevExpress Add ASPxGridView template columns at runtime

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace ...

  3. LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版

    题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...

  4. 2020 ICPC EC Final西安现场赛游记

    也不知道从何说起,也不知道会说些什么,最想表达的就是很累很累. 从第一天去的时候满怀希望,没什么感觉甚至还有一些兴奋.到后来一直在赶路,感觉很疲惫,热身赛的时候觉得马马虎虎,导致热身赛被咕.然后教练就 ...

  5. tornado 学习笔记9 Tornado web 框架---模板(template)功能分析

            Tornado模板系统是将模板编译成Python代码.         最基本的使用方式: t = template.Template("<html>{{ myv ...

  6. Why we need template on Django ?

    Let's create a simple website by django ... step01: django-admin startproject x01 step02: cd x01 ls ...

  7. WPF DataGrid Custommization using Style and Template

    WPF DataGrid Custommization using Style and Template 代码下载:http://download.csdn.net/detail/wujicai/81 ...

  8. Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]

    题目链接:https://codeforces.com/gym/102056/problem/I Warm sunshine, cool wind and a fine day, while the ...

  9. freemarker的template用法

    package cn.itcast.ssm.util; import com.alibaba.fastjson.JSONObject; import freemarker.cache.StringTe ...

随机推荐

  1. luigi学习4-构建工作流

    luigi提供了两个基本单元来构造一个工作流,这两个基本单元分别是Task和Target.这两个单元都是抽象类,我们实现他们中的某些方法就可以了.除了这两个基本单元,还有一个重要的概念是Pramete ...

  2. (原创)Windows8下安装配置WAMP

    Windows8下安装配置WAMP        2013/12/28 最近这段时间一直在研究linuxshell编程,虽然还是初级水平,但比之前有了不小的进度,但是shell的命令很多,很难在短时间 ...

  3. 【Zend Studio】10.6.0版本设置默认字体

    1.打开Windows->Prefefences 2.找到General->Appearance->Colors and Fonts->Basic->Text Font- ...

  4. CentOS7.0安装与配置Tomcat-7

    解决权限不够 #chmod a+x filename 安装说明 安装环境:CentOS-7.0.1406安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址:ht ...

  5. 安装Google框架服务并突破Google Play下载限制

    请注明出处:http://www.cnblogs.com/killerlegend/p/3546235.html Written By KillerLegend 关于谷歌服务框架以及安装 安装前请先获 ...

  6. Map(双列集合)

    出现的原因:现实生活中有些数据成对存在. 特点:键不可重复,值可以重复. ----------|Map                数据都是以键值对的形式存在,键唯一,值可重复. --------- ...

  7. Mysql 简单问题汇总(持续更新)

    主从架构相关问题 问题现象:从机连接主机时报错 [ERROR] Slave I/O: error connecting to master 'repl@192.168.0.50:3306' - ret ...

  8. 第五节:什么导致Finalize方法被调用

    Finalize方法在垃圾回收结束时被调用,下面有5种事件会导致开始垃圾回收 1.第0代已满    第0代已满,垃圾回收会自动开始.该事件是目前导致Finalize方法被调用的最常见的一种方式,因为虽 ...

  9. UICollectionView [NSIndexPath section]: message sent to deallocated instance

    在UICollectionView上加UITapGestureRecognizer手势时,点击哪都报 [NSIndexPath section]: message sent to deallocate ...

  10. sql server 判断是否存在数据库,表,列,视图

    1 判断数据库是否存在if exists (select * from sys.databases where name = '数据库名')    drop database [数据库名] 2 判断表 ...