HackerRank# Red John is Back
简单动归+素数判定,没用筛法也能过
代码:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; #define MAX_N 64
#define MAX_M 1000000 int T, N;
int cnt[MAX_N];
int p[MAX_M]; int is_prime(int n) {
for (int i = ; i * i <= n; i++)
if (n % i == )
return ;
return ;
} int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
p[] = ;
for (int i = ; i < MAX_M; i++)
p[i] = p[i - ] + is_prime(i);
cin >> T;
while (T--) {
cin >> N;
memset(cnt, , sizeof(cnt));
cnt[] = ;
for (int i = ; i <= N; i++)
cnt[i] = cnt[i - ] + (i - >= ? cnt[i - ] : );
cout << p[cnt[N]] << endl;
}
return ;
}
HackerRank# Red John is Back的更多相关文章
- SPOJ:Red John is Back(DP)
Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he ...
- js最好的继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法。
js最好的继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法. function ClassA(sColor) { this.color = sColor; } Class ...
- call(this)引起的对闭包的重新理解
call(this)引起的对闭包的重新理解.md 变量的作用域 全局变量局部变量 Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量. 函数外部无法读取函数内的局部变量. 函数内部 ...
- JavaScript学习笔记(高级部分—02)
47.switch语句的语法: switch (i) { case 20: alert("20"); break; case 30: alert("30"); ...
- Java Script 学习笔记
JS编程习惯类: 1. 命名 著名的变量命名规则 只是因为变量名的语法正确,并不意味着就该使用它们.变量还应遵守以下某条著名的命名规则: Camel 标记法 首字母是小写的,接下来的字母都以大写字符开 ...
- JavaScript 中实现继承的方式(列举3种在前一章,我们曾经讲解过创建类的最好方式是用构造函数定义属性,用原型定义方法。)
第一种:对象冒充 function ClassA(sColor) { this.color = sColor; this.sayColor = function () { alert(this.col ...
- JavaScript 开发总结(一)
数据类型:JavaScript定义的数据类型有字符串.数字.布尔.数组.对象.Null.Undefined,但typeof有区分可判别的数据分类是number.string.boolean.objec ...
- js一种继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法。
js一种继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法. function ClassA(sColor) { this.color = sColor; } ClassA ...
- 关于JavaScript中实现继承,及prototype属性
感谢Mozilla 让我弄懂继承. JavaScript有八种基本类型,函数属于object.所以所有函数都继承自object.//扩展:对象,基本上 JavaScript 里的任何东西都是对象,而且 ...
随机推荐
- 【extjs6学习笔记】0.3 准备:系统架构
- IOS7适配
(1)如果应用程序始终隐藏 status bar 那么恭喜呢,你在UI上需要的改动很少很少. (2)如果应用程序显示status bar,可以讲status bar设置成黑色不透明 ,然后在UIVie ...
- Spring MVC系列[2]——参数传递及重定向
1.目录结构 2.代码 <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...
- red5 重新分配 ip
root@hett-OptiPlex-7040:~# ll /usr/local/src/red5/conf/total 144drwxr-xr-x 2 root root 4096 1月 9 ...
- MVC简单登陆验证
配置文件: <system.web> <authentication mode="Forms"> <!-- 如果验证失败就返回URL的指定界面,设置c ...
- 利用python进行数据分析1_numpy的基本操作,建模基础
import numpy as np # 生成指定维度的随机多维数据 data=np.random.rand(2,3) print(data) print(type(data)) 结果: [[0.11 ...
- Java生成固定长度的随机字符串(以大小写字母和数字)
package org.jimmy.autosearch2019.test; import java.util.ArrayList; import java.util.Random; /** * @a ...
- apache shiro的工作流程分析
本文基于shiro的web环境,用宏观(也就是不精确)的角度去理解shiro的工作流程,先看shiro官方的一张图. 和应用程序直接交互的对象是Subject,securitymanager为Subj ...
- ubuntu 升级到5.1kernel,打开bbr
apt-get -f install wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.1/linux-headers-5.1.0-0 ...
- Spring框架中的aop操作之一 及aspectjweaver.jar与aopalliance-1.0.jar下载地址 包含beans 注解context 和aop的约束
(aspect oriented programming面向切面编程) 首先在原有的jar包: 需Spring压缩包中的四个核心JAR包 beans .context.core 和expression ...