题干:

After the 1997/1998 Southwestern European Regional Contest (which was held in Ulm) a large contest party took place. The organization team invented a special mode of choosing those participants that were to assist with washing the dirty dishes. The contestants would line up in a queue, one behind the other. Each contestant got a number starting with 2 for the first one, 3 for the second one, 4 for the third one, and so on, consecutively. 
The first contestant in the queue was asked for his number (which was 2). He was freed from the washing up and could party on, but every second contestant behind him had to go to the kitchen (those with numbers 4, 6, 8, etc). Then the next contestant in the remaining queue had to tell his number. He answered 3 and was freed from assisting, but every third contestant behind him was to help (those with numbers 9, 15, 21, etc). The next in the remaining queue had number 5 and was free, but every fifth contestant behind him was selected (those with numbers 19, 35, 49, etc). The next had number 7 and was free, but every seventh behind him had to assist, and so on.

Let us call the number of a contestant who does not need to assist with washing up a lucky number. Continuing the selection scheme, the lucky numbers are the ordered sequence 2, 3, 5, 7, 11, 13, 17, etc. Find out the lucky numbers to be prepared for the next contest party.

Input

The input contains several test cases. Each test case consists of an integer n. You may assume that 1 <= n <= 3000. A zero follows the input for the last test case.

Output

For each test case specified by n output on a single line the n-th lucky number.

Sample Input

1
2
10
20
0

Sample Output

2
3
29
83

解题报告:

这题刚开始就想错了,简单的想成了素数问题,所以上来就是个线性筛,结果wa了。。。后来一想发现并不是素数问题,因为在这种模式下有的素数是要被筛掉的。主要是因为这个题意:是数到第k个还健在的数字,并且筛掉这个数字,这就导致了,筛掉的数字不全是素数,也有一部分是合数,因为这里找到的i并不是数学上的约数的意义,换句话来讲,此时的i不是+i了,而有可能是+(i+1),或是+(i+3),+(i+2)等等、、、

ps :  这个打表的时间复杂度好像不是很好解释?暂时弄不明白、、、

AC代码:

//打表、、
#include<bits/stdc++.h>using namespace std;bool prime[40004];
int lucky[3005];
int n;
int main()
{memset(prime,1,sizeof prime);for(int i = 1; i<=3000; i++) {for(int j = 2; j<=40000; j++) {if(prime[j]) {lucky[i] = j;prime[j]=0;int sum = 0;for(int k = j+1; k<=40000; k++) {if(prime[k]) {sum++;if(sum % j == 0) prime[k] = 0;}}break;}}}while(scanf("%d",&n)) {if(n == 0 ) break;printf("%d\n",lucky[n]);}return 0 ;
}

【HDU - 1216 】Assistance Required (模拟,类似素数打表,不是素数问题!)相关推荐

  1. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  2. HDU 3328 Flipper 栈 模拟

    HDU 3328 Flipper 栈 模拟 首先想说,英语太烂这题读了很长时间才读懂......题意是说输入有几张牌,然后输入这些牌的初始状态(是面朝上还是面朝下),然后输入操作方式,R表示翻一下右边 ...

  3. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  4. UVA 10006(卡迈克尔数+素数打表)

    uva10006 Carmichael Numbers(卡迈克尔数+素数打表) 发表于2017/2/20 21:43:25  16人阅读 分类: 其他oj 数论-组合数学 https://uva.on ...

  5. [油猴脚本开发指南]脚本自动化之模拟点击和表单填写

    转载自油猴中文网:bbs.tampermonkey.net.cn 李恒道QQ4548212 油猴中文网bbs.tampermonkey.net.cn TamperMonkey GreaseMonkey ...

  6. 关于表单的java的程序_JAVA BOT程序模拟人类用户填写表单 并 发送

    仿真表单:BOT程序模拟人类用户填写表单 并 发送 抓取表单: HTTPSocket http = new HTTPSocket(); SocketFactory.setProxyHost(" ...

  7. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  8. 筛法求素数 素数打表

    c++ #include<cstdio> #include<cstring> #include<cmath>//素数打表 ,时间复杂度:O(nlog n) char ...

  9. LightOJ-1220 Mysterious Bacteria (素数打表+欧几里得算法+唯一分解定理)给出x,求x=a^p,最大的指数

    题目大意: x = b^p, x只有一个因子的p次幂构成 如果24 = 2^3*3^1,p应该是gcd(3, 1) = 1,即24 = 24^1 324 = 3^4*2^2=(3^2*2)^2,p应该 ...

最新文章

  1. 服务器自动安全审计,用于Linux服务器的自动安全审计工具
  2. 请教于国富律师——怎样把灰鸽子病毒和灰鸽子程序区分开
  3. 【百度地图API】如何使用suggestion--下拉列表方式的搜索建议
  4. quartz可以指定方法名吗_大理石可以自己抛光吗?大理石自己抛光方法解答
  5. boost::geometry::remove_spikes用法的测试程序
  6. sap.ui.viewModifications view extension
  7. 注解 @ModelAttribute 运用详细介绍
  8. 2020最常用的8个代码编辑器推荐
  9. 论文赏析[NAACL18]神经成分句法分析器的一些分析
  10. remote collaboration on physical tasks 应用
  11. python 相关性检验_Python中的相关分析correlation analysis的实现
  12. Vue项目的打包\部署\优化
  13. nginx通过获取环境变量实现动态IP代理配置
  14. (附源码)Springboot大学生综合素质测评系统 毕业设计 162308
  15. 万字长文浅析:Epoll的那些事儿
  16. 改变 Windows 用户文件夹默认位置
  17. Eclipse怎么设置字体呢
  18. python 基础知识(1)
  19. 比尔-盖茨出席新世代厕所博览会,展示新一代卫生产品
  20. 一花独放不是春 梆梆安全呼吁构建物联网安全共同体

热门文章

  1. [Leetcode][第214题][JAVA][最短回文串][KMP][RK]
  2. 【数据结构与算法】二分查找
  3. java interfaceof,java interface教程
  4. 安川最小巧机器人_2020工博会,安川展品前瞻(机器人篇)
  5. 从setTimeout,onclick传参看js函数作为参数
  6. Qt 编码问题QTextCodec
  7. android平台的s5pc110触摸屏驱动分析
  8. ARM中断分析之四:WinCE的OAL层的中断分析
  9. Windows Embedded CE 6.0开发初体验(六)平台定制
  10. linux 网络相关,Linux系统管理员必备的21个网络相关监控