二维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. PHP isset()与empty()的区别详解

    通过对PHP语言的学习,应该知道它是基于函数的一款HTML脚本语言. 庞大的函数库支持着PHP语言功能的实现. 有关PHP函数isset()与empty()的相关用法. PHP的isset()函数 一 ...

  2. Linux Shell脚本编程的注意事项

    Linux下(Shell脚本 http://www.jbxue.com/jb/shell/)编程的一些注意事项,如编程风格.命名风格等. 一.常用技巧 ssh user@server bash < ...

  3. 主键、外键、超键、候选键的区别【Written By KillerLegend】

    先说一下属性的定义: 表的每一行对应一个元组,表的每一列对应一个域.由于域可以相同,为了加以区分,必须对每列起一个唯一的名字,称为属性(Attribute). 再来看看几个键的定义: 超键:在关系模式 ...

  4. C# 判断是否为闰年的条件各是

    //try 没增加异常数据处理 Console.WriteLine("根据输入的信息计算当年某个月份的天数,以及当年是否是闰年或平年,\n并判断2月份特殊月份的天数."); Con ...

  5. 010-python基础-数据类型-字符串操作

    1.移除空白 username.strip() 2.分割 names = "alex,jack,rain" names_1 = names.split(",") ...

  6. LPHW-积累-ex1-6

    Learn Python The Hard Way  ex0  介绍了各个操作系统下python的安装:强调了初学者最好使用简单的编辑器,不要使用IDE环境 ex1 使用 print 输出简单的字符串 ...

  7. C#调用C++ Dll

    现在项目基本都是旁边C++的哥们做好dll扔给我,然后我调用.好久之前晚上down了一份c#调用c++dll的方法,出处早已经遗忘.闲来无事,放上来好了.原作者看到后可以留言,我会把您链接放上的,帮了 ...

  8. Java当中的I/O的字符流

    字符流读写文件时,以字符为基础 I/O当中字符流的核心类 Reader类和Writer类是所有字符流类的父类,同样也是抽象类.FileReader和FileWriter分别是它们的子类. 核心类的核心 ...

  9. 【J2EE】Hibernate

    Hibernate是面向Java环境的对象/关系数据库映射工具,管理Java应用和数据库之间的映射关系,提供数据查询和获取数据的方法,可以大幅减少使用JDBC处理数据持久化的时间. 使用Eclipse ...

  10. 算法系列2《RSA》

    1. RSA介绍 RSA公钥加密算法是1977年由Ron Rivest.Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的.RSA取名来自开发他们三者的名字.RSA是目前最有影响 ...