1795 The least one【素数打表】
2015-08-01 15:43
337 查看
The least one
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 423 Accepted Submission(s): 149
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
3
7
[align=left]Sample Output[/align]
5
11
这个题比较简单......
最重要的是读懂题意,题意说的是.....
给你一个数,代表有一群编号为 1~m 的怪物,需要你派遣一个人去杀怪物,而且杀怪物的数量不能少于给出的怪物数量,规定的屠杀怪兽的规则是人的能力要高于怪兽的能力,且怪兽和人的能力值不能有除 1 外的公因子!.....
这样一分析,就发现问题变简单了............就是找到大于这个数的最小素数!!!
题解:
先打个素数表,然后就从这个元素开始往更大的方向开始查找.........
找到后就直接输出........
#include<stdio.h> int x[1000005]; int main() { int t,n,i,j; x[1]=0; for(i=2;i<1000005/i;++i)//打表........ { if(x[i]==0) { for(j=2;j<1000005/i;++j) { x[i*j]=1; } } } scanf("%d",&t); while(t--) { scanf("%d",&n); ++n; while(x !=0)//查找....... { ++n; } printf("%d\n",n);//输出.......... } return 0; }
相关文章推荐
- 性能测试报告模板 V1.0
- 编程修养(六)
- 【转】通过编程自动化增加CSDN博客的访问量
- Java实现文件的RSA和DES加密算法
- 南阳oj 郁闷的c小加(一) 题目257
- R语言:k近邻
- 【NOIP2006】金明的预算方案
- 异常
- pdfFactory Pro 不能被安装(AddPrinterDriver 失败)...找不到指定的模块
- 编程修养(五)
- 通过位置找到ListView中的某个item的View
- mysql存储过程之游标遍历数据表
- margin外边距问题
- Swing 中各种提示框的工具类
- webstrom 安装教程 配置js调试
- 【练习笔记】剑指offer-面试题7 :用两个栈实现队列
- JS 解析JSON
- Single Number(找出只出现了一次的数,其它数都出现两次)
- c# ConcurrentQueue
- [odroid-pc] ubuntu12.04 安装jdk-6u45-linux-x64.bin