HDU 1216 Assistance Required 埃拉托色尼色筛法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1216
思路:色筛法
代码(1):
#include<iostream>//--------1216 HDU 埃拉托色尼筛选法
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;
#define Max 40000
bool b[Max];
__int64 a[Max], c;
void fun()
{
__int64 i, j, count;
c = ;
memset(b, true, sizeof(b));
b[] = ;
for (i = ; i < Max; ++i)
{
if (b[i])
{
a[++c] = i;
count = i;
for (j = i+; j < Max; ++j)
{
if (b[j] == true)
count--;
if (count == )
{
b[j] = false;
count = i;
}
}
}
}
}
int main()
{
fun();
int n;
while (scanf("%d", &n) != EOF)
{
if (n == )
break;
else
printf("%d\n", a[n]);
}
return ;
}
基本类似的另外一种:
#include<iostream>
#include<stdio.h>
#include<cstdlib>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define Max 40000
__int64 ans[Max];
__int64 pop[];
void dfs()
{
__int64 i, j, count;
for (i = ; i < Max; i++)
{
ans[i] = i;
}
for (i = ; i < Max; i++)
{
if (ans[i] != )
{
count = i;
for (j = i + ; j < Max; j++)
{
if (ans[j] != )
count--;
if (count == )
{
ans[j] = ;
count = i;
}
}
} }
j = ;
for (i = ; i <= ; i++)
{
while (ans[j] == )
{
j += ;
}
if (ans[j] != )
{
pop[i] = ans[j];
j += ;
}
}
}
int main()
{
dfs();
int n;
while (scanf("%d", &n)&&n)
{
printf("%d\n", pop[n]);
}
return ;
}
HDU 1216 Assistance Required 埃拉托色尼色筛法的更多相关文章
- HDU 1216 Assistance Required(暴力打表)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...
- 2015 HDU 多校联赛 5317 RGCDQ 筛法求解
2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目 http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...
- 埃拉托色尼(Eratosthenes)筛法
用筛选法求1—100之内的素数(此法难度的话,方法可以不界定:能完成求1—100之内的素数即可). 在一张纸上写上1到100全部整数,然后逐个判断它们是否是素数,找出一个非素数,就把它挖掉,最后 ...
- SP1798 ASSIST - Assistance Required 题解
Content 有一个足够长的数列 \(a\),是一个首项为 \(2\),公差为 \(1\) 的等差递增数列.另有一个初始为空的数列 \(b\). 重复进行如下操作: 假设当前数列 \(a\) 第一项 ...
- 2018年暑假ACM个人训练题7 题解报告
A:HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用) B:(还需要研究一下.....) C:HDU 1071 The area(求三个点确定的抛物线的面积, ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 给swift程序猿留下深刻印象的10个Swift代码
通过使用单行代码完成同样的 10 个练习,我们来看看 Swift 和其他语言之间的较量. 将数组中每个元素的值乘以 2 使用map来实现 var arr = [1,2,3,4]; var newArr ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
随机推荐
- MongoDB监控
1. mongostat:间隔固定时间获取mongodb的当前运行状态,并输出. 使用示例: D:\Program_Files\MongoDB\bin\mongostat(根据MongoDB的安装目录 ...
- Linux系统Shell脚本编程
1. shell脚本概念:C语言编写的.命令解释器.编程语言. 是用户使用linux的桥梁. shell脚本语言非常擅长处理文本类型的数据. 2. shell脚本作用:自动化管理.监控管理.日志数据处 ...
- expected single matching bean but found 2
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...
- Android_简易的短信发送器
这个随笔将介绍如何完成一个简单的第三方的短信发送器(不打开短信界面,调用android的api完成功能) 1.首先,我们来做布局 由于我这里写的是一个简易的,,短信发送,所以只是一个LinearLay ...
- win10 安装Node.js 报错:2503
解决方法: 使用管理员打开CMD
- lua State加载部分库
lua State加载部分库 在lua中,通常我们用luaL_openlibs(L)加载所有的lub标准库,但是有时候我们想只加载部分,有没有什么好的办法呢?在luaproc看到如下办法: stati ...
- Problem A
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 还原NuGet程序包
官网:https://msdn.microsoft.com/zh-cn/magazine/hh547106.aspx 在获取团队中的项目或者下载他人的项目Demo后,运行项目有时会提示某些dll找不到 ...
- JsDoc脚本注释文档生成
使用jsDoc可使用特定注释,将注释的内容生成文档,可用于生成脚本库的API文档 jsdoc 文档: http://usejsdoc.org/