hdu 1216 Assistance Required

简介: hdu 1216 Assistance Required

Assistance Required

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3360    Accepted Submission(s): 1761


 

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.

 

 

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

 

 

Source

University of Ulm Local Contest 2002

 

理解了题意之后本体并不难,直接暴力可AC。

 

代码如下:

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j=0,k=0,l=0,N,f[34005]={0},F[3001];
    for(i=2;i<34000;i++)
    {
        l=0;
    if(f[i]==0)
    {
        F[k]=i;
        k++;
    for(j=i+1;j<34000;j++)
    {
        if(f[j]==0) l++;
        if(l==i) {f[j]=1;l=0;}
    }
    }
    }
while(scanf("%d",&N)!=EOF&&N)
{
printf("%d\n",F[N-1]);
}
return 0;
}
目录
相关文章
|
存储 缓存 网络安全
在局域网内访问项目时遇到了OSS路径错误的问题
在局域网内访问项目时遇到了OSS路径错误的问题
1062 2
|
Ubuntu 网络协议 应用服务中间件
ubuntu配置nginx反向代理
ubuntu 配置nginx反向代理,这里简单记录下,后续再复习..
ubuntu配置nginx反向代理
|
7月前
|
存储 Cloud Native 关系型数据库
PolarDB开源:云原生数据库的架构革命
本文围绕开源核心价值、社区运营实践和技术演进路线展开。首先解读存算分离架构的三大突破,包括基于RDMA的分布式存储、计算节点扩展及存储池扩容机制,并强调与MySQL的高兼容性。其次分享阿里巴巴开源治理模式,涵盖技术决策、版本发布和贡献者成长体系,同时展示企业应用案例。最后展望技术路线图,如3.0版本的多写多读架构、智能调优引擎等特性,以及开发者生态建设举措,推荐使用PolarDB-Operator实现高效部署。
398 3
|
存储 分布式计算 Hadoop
HadoopCPU、内存、存储限制
【7月更文挑战第13天】
771 14
|
11月前
|
人工智能 编解码 自然语言处理
CogView-3-Flash:智谱首个免费AI图像生成模型,支持多种分辨率,快速生成创意图像
CogView-3-Flash 是智谱推出的首个免费AI图像生成模型,支持多种分辨率,快速生成高质量图像,广泛应用于广告、设计、艺术创作等领域。
412 6
CogView-3-Flash:智谱首个免费AI图像生成模型,支持多种分辨率,快速生成创意图像
|
固态存储 测试技术 图形学
电脑升级有哪些建议?
【10月更文挑战第31天】电脑升级有哪些建议?
626 4
|
机器学习/深度学习 人工智能 自动驾驶
深度学习的奇迹:如何用神经网络识别图像
【10月更文挑战第33天】在这篇文章中,我们将探索深度学习的奇妙世界,特别是卷积神经网络(CNN)在图像识别中的应用。我们将通过一个简单的代码示例,展示如何使用Python和Keras库构建一个能够识别手写数字的神经网络。这不仅是对深度学习概念的直观介绍,也是对技术实践的一次尝试。让我们一起踏上这段探索之旅,看看数据、模型和代码是如何交织在一起,创造出令人惊叹的结果。
192 0
|
NoSQL Java 关系型数据库
开源系统推荐短信网关
开源系统推荐短信网关
409 0
|
网络协议
IPTables六—— IPTable规则优化IPSet
六、IPSet iptables在进行包过滤的时候,对每个数据包都过滤一遍iptables中的规则。假设我们有如下三条规则: -s 1.1.1.1 -p tcp accpet -s 2.2.2.2 -p tcp accpet -s 3.3.3.3 -p tcp accpet 那么当一个数据包源地址是3.3.3.3的时候,它首先去匹配第一条规则,不匹配再匹配第二条,最后在第三条匹配中了。
1500 0
|
缓存 前端开发 JavaScript
除了SSR、CSR、还有ISR、SSG?🚀🚀🚀五分钟搞懂它们的区别
除了SSR、CSR、还有ISR、SSG?🚀🚀🚀五分钟搞懂它们的区别