HDU 1216 Assistance Required
来源:互联网 发布:香港陈枝记铁锅淘宝网 编辑:程序博客网 时间:2024/05/06 09:00
Assistance Required
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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.
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
1210200
Sample Output
232983
这题不是筛素数。。。题意是:
第一个同学是2号,给真票,从2号同学的下一个为第一个到最后一个同学之间没有给票的同学记数,每第二个没给票的同学给一张假票,然后再从头开始找出排在前边没给票的同学,给真票,这时候是3号同学没给票,给真票,然后从3号的下一个没给票的同学开始到最后一个没给票的同学结束,即从5开始(4号已经给了假票)每三个没给票的同学为一个单位,给第三个同学假票,以此类推,
第一个同学是2号,给真票,从2号同学的下一个为第一个到最后一个同学之间没有给票的同学记数,每第二个没给票的同学给一张假票,然后再从头开始找出排在前边没给票的同学,给真票,这时候是3号同学没给票,给真票,然后从3号的下一个没给票的同学开始到最后一个没给票的同学结束,即从5开始(4号已经给了假票)每三个没给票的同学为一个单位,给第三个同学假票,以此类推,
#include <iostream>#include <stdio.h>#include <memory.h>using namespace std;int lucky[40000],ans[40000];int main(void){ memset(lucky,0,sizeof(lucky)); memset(ans,0,sizeof(ans)); int k=1; for(int i=2;i<=40000;i++) { if(ans[i]==0) { lucky[k++]=i; int j=0; int l=i+1; while(l<=40000) { if(ans[l]==0) { j++; } if(j==i) { // printf("i: %d j: %d l: %d\n",i,j,l); ans[l]=1; j=0; } l++; } } } int n; while(scanf("%d",&n)!=EOF&&n) { printf("%d\n",lucky[n]); } return 0;}
0 0
- hdu 1216 Assistance Required
- HDU 1216 Assistance Required
- HDU 1216 Assistance Required
- hdu-1216-Assistance Required
- hdu 1216 Assistance Required
- hdu 1216 Assistance Required
- HDU 1216 Assistance Required(模拟)
- HDOJ 1216 Assistance Required
- HDUOJ 1216 - Assistance Required
- ZOJ 1978 && HDU 1216 && POJ 2552 Assistance Required (筛选)
- hdu 1216 Assistance Required(数学:打表)
- HDU1216--Assistance Required HDU(92)
- Assistance Required
- Assistance Required
- Assistance Required
- Assistance Required
- 1216Assistance Required(筛选法模拟题意)
- 杭电ACM-1216-Assistance Required
- Android基于XMPP Smack Openfire下学习开发IM(五)连接断开重连
- zip解压文件java
- ASP.net问题总结
- C++面试资料之问答题集合(找工作复习)
- 动态给Sharepoint的列表的三个Form添加Webparts
- HDU 1216 Assistance Required
- Android基于XMPP Smack Openfire下学习开发IM(六)总结
- Java生成验证码
- IIS php 站点上传图片 图片存在不能访问 没有用户权限
- 08-3. Sort with Swap(0,*)
- 基于lucene的案例开发:更新说明
- 如何截取字符串?
- Activity生命周期
- 程序员笔试知识点整理