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 里的任何东西都是对象,而且 ...
随机推荐
- Objective-C language
Objective-C is the primary language used to write Mac software. If you're comfortable with basic obj ...
- spark常用参数
val conf = new SparkConf().setAppName("WordCount_groupBy").setMaster("local") // ...
- python中中括号中的负数
>>> a="a,b,c,d,e">>> a.split(",")[0:2]['a', 'b']>>> a ...
- js 双向绑定
//双向绑定实例 <input name="" ng-bind-123="name" /> function DataBinder( object_ ...
- Sublime Text3括号配对与代码包围效果BracketHighlighter
就这么看json等配置文件,太难了,我们需要括号匹配插件BracketHighlighter,但是装完以后只有下划线提示不明显,需要配置 Bracket Settings-Default 文件 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- crontab 应用
可以用crontab -e 添加要执行的命令. 命令执行的结果,无论是标准输出还是错误输出,都将以邮件形式发给用户. 添加的命令必须以如下格式: * * * * * /co ...
- 几个不错的APP网站。
http://www.yunshipei.com/yunshipei.html http://www.appcan.cn/
- for循环输出i为同一值的问题
使用闭包将变量i的值保护起来. //sava1:加一层闭包,i以函数参数形式传递给内层函数 for( var i=0; i<ps.length; i++ ) { (function(arg){ ...
- MFC:AfxLoadLibrary-将指定的 DLL 映射到调用进程的地址空间
Visual Studio 2012 - Visual C++ LoadLibrary 和 AfxLoadLibrary 进程调用 LoadLibrary (或 AfxLoadLibrary) 以显式 ...