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. 24种设计模式--模版方法模式【Template Method Pattern】

    周三,9:00,我刚刚坐到位置,打开电脑准备开始干活.“小三,小三,叫一下其它同事,到会议室,开会”老大跑过来吼,带着淫笑.还不等大家坐稳,老大就开讲了,“告诉大家一个好消息,昨天终于把牛叉模型公司的 ...

  2. mouseover和mouseout事件在鼠标经过子元素时也会触发

    JavaScript的mouseover和mouseout事件,在绑定元素内部有子元素的情况下, 经过绑定元素时会多次触发mouseover和mouseout事件. jQuery解决办法: jquer ...

  3. bootstrap上传表单的时候上传的数据默认是0 一定要小心

    bootstrap上传表单的时候上传的数据默认是0 一定要小心

  4. hibernate映射

    三种方式:     持久化注解   目前开发主流方式     XML配置描述文件(XML deployment descriptor,可以让Hibernate的PO类与JPA实体类兼容,实际中很少用) ...

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

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

  6. Successfully installed matplotlib

    Installing /usr/local/lib/python2.7/dist-packages/matplotlib-1.4.0-py2.7-nspkg.pthSuccessfully insta ...

  7. virtalBox共享文件夹设置

    sudo mount -t vboxsf gongxiang /mnt/shared/

  8. iOS 仪表式数字跳动动画-b

    前几天搞了 双曲线波浪动画(http://www.jianshu.com/p/7db295fd38eb)和环形倒计时动画(http://www.jianshu.com/p/d1d16dff33c9)而 ...

  9. 如何分析matlab程序的主要效率问题

    利用profile on 在需要分析效率的程序段前后加入 profile on profile off 然后,在common line中输入profile viewer即可观察到这段程序的效率

  10. Maven镜像配置

    镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... <mirrors> <mirror ...