add some template for ec-final
二维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的更多相关文章
- [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; ...
- DevExpress Add ASPxGridView template columns at runtime
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace ...
- LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版
题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...
- 2020 ICPC EC Final西安现场赛游记
也不知道从何说起,也不知道会说些什么,最想表达的就是很累很累. 从第一天去的时候满怀希望,没什么感觉甚至还有一些兴奋.到后来一直在赶路,感觉很疲惫,热身赛的时候觉得马马虎虎,导致热身赛被咕.然后教练就 ...
- tornado 学习笔记9 Tornado web 框架---模板(template)功能分析
Tornado模板系统是将模板编译成Python代码. 最基本的使用方式: t = template.Template("<html>{{ myv ...
- Why we need template on Django ?
Let's create a simple website by django ... step01: django-admin startproject x01 step02: cd x01 ls ...
- WPF DataGrid Custommization using Style and Template
WPF DataGrid Custommization using Style and Template 代码下载:http://download.csdn.net/detail/wujicai/81 ...
- 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 ...
- freemarker的template用法
package cn.itcast.ssm.util; import com.alibaba.fastjson.JSONObject; import freemarker.cache.StringTe ...
随机推荐
- IIS 7.5 配置Asp+Access的几点注意的地方
环境:window2008 R2 + iis 7.51 把网站程序放在一个www文件夹里面,给这个文件夹添加everyone的用户,赋予全部读写权限,这样安全些.2 选中要配置的网站,点击页面中间“A ...
- 删除linux系统服务
#删除服务的命令,[ServiceName]需要替换为实际的服务名称 sudo update-rc.d [ServiceName] remove 有时候安装sysv-rc-conf进行服务控制,但是在 ...
- 代码分享:php对二维数组进行排序
发布:net/PHP编程 编辑:thebaby 2013-06-28 13:12:54 [大 中 小] 转自:http://www.jbxue.com/article/9991.html本文介 ...
- ArrayAdapter的简单使用
1.创建一个类继承ArrayAdapter private class MyAdapter extends ArrayAdapter { LayoutInflater in; Context cont ...
- Ubuntu kylin系统改中文系统文件名为英文
刚装好系统,将使用语言改成了中文,结果重启后,提示是否将文件系统的名字改为新的,我一不注意,点了是...这样,在以后使用终端的时候,会有中文来干扰,所以需要改回英文. 方法如下: 输入两个命令即可: ...
- 4.css度量单位
在 CSS 长度设置中,我们经常需要使用到度量单位,即以什么样的单位设计我们的字 体或边框长度.而在 CSS 中长度单位又分为绝对长度和相对长度. 绝对长度指的是现实世界的度量单位,CSS 支持五种绝 ...
- swift 2
... ..< func a(inout a) //by ref use &xx Parameters passed to functions are constants by de ...
- properties文件
properties文件也叫资源文件,以键值对的形式存放文本内容.一个properties对象代表一个资源文件 步骤:1.生成properties对象2.生成InputStream/Reader来读取 ...
- 解惑:NFC手机如何轻松读取银行卡信息?
自支付宝钱包8.0推出了NFC新功能,只要将支持NFC功能的手机靠近公交卡.银行卡等带有芯片的IC卡上,可迅速读取卡内余额.卡的信息,还可以给卡进行充值,非常贴心实用. 但是很多网友表示担忧,要是别人 ...
- 【6.24-AppCan移动开发大会倒计时】科大讯飞来了!
6.24 AppCan移动开发者大会进入倒计时,报名通道即将关闭! 50多家移动圈服务商将出席此次大会,讯飞开放平台也将作为参展商,为参会者带去前沿的语音技术.参会者可现场体验最新连续语音识别技术,识 ...