hdoj 1795 The least one 【简单题】
2015-08-01 15:49
253 查看
The least one
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 418 Accepted Submission(s): 147
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
题意:求大于Q的且与Q互质的最小的数。
AC代码:
#include <cstdio> #include <cstring> #include <cmath> bool judge(int x) { for(int i = 2; i <= sqrt(x); i++) if(x % i == 0) return false; return true; } int main() { int t; scanf("%d", &t); while(t--) { int Q; scanf("%d", &Q); for(int i = Q + 1; ; i++) { if(judge(i)) { printf("%d\n", i); break; } } } return 0; }
相关文章推荐
- [二分+贪心] poj 2456 Aggressive cows
- Surrounded Regions --LeetCode
- struts2-spring-plugin.jar的一些感悟
- C/C++刷题知识点总结
- 修改 Servlet 模板
- csdn论坛服务能再烂点吗,老崩
- UVa10054 The Necklace (欧拉回路)
- pyqt 取值
- 【Entity Framework】初级篇--ObjectContext、ObjectQuery、ObjectStateEntry、ObjectStateManager类的介绍
- 【加密与解密】C#如何读取pem的KEY文件
- 黑马程序员 第七篇 继承 (part 1) (Foundation; completed)
- hdoj 5112 A Curious Matt(水题)
- 9.2链表(二)——找出单向链表中倒数第k个节点
- gcc 编译器常用的命令行参数一览
- [odroid-pc] ubuntu12.04 android4.0移植到odroid-pc过程
- iWatch error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle ident
- http简介
- 关于Eclipse生成和导入Patch文件.
- POJ3468——线段树成段更新——A Simple Problem with Integers
- 在SD卡上创建/删除文件夹 使用DDMS透视图管理SD卡