The least one

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 492    Accepted Submission(s):
184

Problem Description
  In the RPG game “go back ice age”(I decide to develop
the game after my undergraduate education), all heros have their own respected
value, and the skill of killing monsters is defined as the following rule: one
hero can kill the monstrers whose respected values are smaller then himself and
the two respected values has none common factor but 1, so the skill is the same
as the number of the monsters he can kill. Now each kind of value of the
monsters come. And your hero have to kill at least M ones. To minimize the
damage of the battle, you should dispatch a hero with minimal respected value.
Which hero will you dispatch ? There are Q battles, in each battle, for i from 1
to Q, and your hero should kill Mi ones at least. You have all kind of heros
with different respected values, and the values(heros’ and monsters’) are
positive.
 
Input
  The first line has one integer Q, then Q lines
follow. In the Q lines there is an integer Mi, 0<Q<=1000000,
0<Mi<=10000.
 
Output
  For each case, there are Q results, in each result,
you should output the value of the hero you will dispatch to complete the
task.
 
Sample Input
2
3
7
 
Sample Output
5
11
题意:就是求比所给数据大的最近的素数
#include<stdio.h>
#include<string.h>
#define MAX 10010
int su[MAX];
void prime()
{
int i,j;
memset(su,0,sizeof(su));
for(i=2;i<MAX;i++)
{
if(!su[i])
{
for(j=i*2;j<MAX;j+=i)
su[j]=1;
}
}
su[1]=1;
}
int main()
{
int t,n,m,j,i;
scanf("%d",&t);
prime();
while(t--)
{
scanf("%d",&n);
for(i=n+1;i<MAX;i++)
{
if(su[i]==0)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}

  

杭电 1795 The least one的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  3. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  4. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  5. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  6. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  7. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  8. 杭电ACM2092--整数解

    杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...

  9. 杭电2034——人见人爱A-B

    #include <stdio.h> #include <algorithm> using namespace std; int main () { int a[110],b[ ...

随机推荐

  1. Repeater 动态增加删除一行

    文章参考:文章参考http://www.cnblogs.com/dataadapter/archive/2012/06/25/2562885.html 效果: 前台代码: <%@ Page La ...

  2. 用原生js实现一个页面乘法口诀表

    今天我自己用js实现了一个页面乘法口诀表(如图)来共享给大家,做的不是很好,如果大家有新的想法可以跟我交流哦. 代码如下: <!doctype html><html lang=&qu ...

  3. Android 中LinearLayout控件属性

    id             为控件指定相应的ID        text           指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符        g ...

  4. node初步一:HTTP请求

    一. 创建pathtest.js文件 var http= require('http' ); var url= require('url' ); function start (){ function ...

  5. angular 实例笔记之嵌套指令间的传参

    最近在项目中遇到了需要嵌套指令的情况,指令在嵌套后子指令必须获得父指令中的数据来进行判断,但是在写传参的时候遇到了坑,因此记录下来,防止以后遗忘,个人的肤浅理解,欢迎大家留言讨论 首先,关于direc ...

  6. Ajax请求ashx一般处理程序实现文件下载

    具体功能为,在文件数据列表中选择一行,点击表格上方的下载按钮,下载文件.由于表格中不包含文件路径,只能取到在数据库表中的ID,所以具体实现就是这样:首先点击一行,获取点击的一行数据的ID,用Ajax传 ...

  7. Android开源项目(转载)

    第一部分 界面 ImageView.ProgressBar及其他如Dialog.Toast.EditText.TableView.Activity Animation等等. 一.ListView an ...

  8. python【第十一篇】消息队列RabbitMQ、缓存数据库Redis

    大纲 1.RabbitMQ 2.Redis 1.RabbitMQ消息队列 1.1 RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议 ...

  9. error proc

    /*************************************************************************\ * Copyright (C) Michael ...

  10. BZOJ 4013 实验比较

    Description 小D被邀请到实验室,做一个跟图片质量评价相关的主观实验.实验用到的图片集一共有\(N\)张图片,编号为\(1\)到\(N\).实验分若干轮进行,在每轮实验中,小\(D\)会被要 ...