HackerRank# Red John is Back
2024-08-31 19:59:28
简单动归+素数判定,没用筛法也能过
代码:
#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 ;
}
最新文章
- dom 操作
- OstrichNet 简易统计信息收集工具
- 简单的方向传感器SimpleOrientationSensor
- #!/usr/bin/env python与#!/usr/bin/python的区别
- log4j配置文件详解
- centos上手动编译安装tmux的问题
- python_递归
- hdu 5326 Work
- css属性
- 2014年辛星完全解读Javascript第二节
- Java JSON序列化杂谈
- css(html)背景图优化合并
- Python安装及开发环境配置
- 线段树解Insertion Sort Advanced Analysis
- 简单的刷票系统(突破IP限制进行投票) (转)
- 201521123045 《JAVA程序设计》第1周学习总结 1
- Angular Universal(统一平台)笔记
- 记录日常Linux常用软件
- 媒体查询@media 屏幕适配
- office2013 Word 缺少校对工具,按提示下载、安装了文件还是不成功的解决方案