Assistance Required
来源:互联网 发布:拳皇14出招优化 编辑:程序博客网 时间:2024/05/16 12:42
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
模拟
#include<stdio.h>#include<iostream>using namespace std;bool book[50000]={1,1,0};int main(){int an[3005]={0},i;for(int k=1;k<=3000;k++){int cnt;for(i=an[k-1]+1;book[i];i++);an[k]=i,cnt=i;for(int j=i+1;j<50000;j++){if(book[j]==false)cnt--;if(!cnt){cnt=i;book[j]=true;}}}int n;while(scanf("%d",&n),n)printf("%d\n",an[n]);return 0;}
阅读全文
0 0
- Assistance Required
- Assistance Required
- Assistance Required
- Assistance Required
- Assistance Required 特殊数组
- hdu 1216 Assistance Required
- HDU 1216 Assistance Required
- HDU 1216 Assistance Required
- HDOJ 1216 Assistance Required
- HDUOJ 1216 - Assistance Required
- hdu-1216-Assistance Required
- hdu 1216 Assistance Required
- Assistance Required(打表)
- HDOJ1216 Assistance Required 打表
- Assistance Required--不定长数组
- POJ 2552 Assistance Required gcc编译器问题
- hdu 1216 Assistance Required
- 1216Assistance Required(筛选法模拟题意)
- hadoop搭建过程中设置FQDN(完全限定域名)
- api接口的数字签名
- python enumerate用法总结
- mybaties
- 欢迎使用CSDN-markdown编辑器
- Assistance Required
- 使用VisualVM监控远程服务器JVM+原创离线安装VisualGC插件
- python斐波那契数列集锦(Fibonacci sequence)
- Darknet yolo 环境搭建以及训练测试自己的数据集
- 【Java】StringUtils工具类常用方法详解
- 洛谷p1006传纸条
- 聊聊ES7与ES8特性
- 3d data set
- 一些问题解答