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;
}
目录
相关文章
|
12月前
|
监控 数据挖掘 API
拼多多API应用:社交分享驱动销量飙升!
本文介绍如何通过拼多多开放平台API实现社交分享功能,利用微信、QQ等社交网络提升商品曝光与销量。结合技术步骤与Python代码示例,详解注册认证、API调用、回调跟踪及优化策略,助力开发者实现销量指数级增长。
|
人工智能 自然语言处理 物联网
从“通用AI”到“懂我AI”:企业微调专属智能助手实战指南
从“通用AI”到“懂我AI”:企业微调专属智能助手实战指南
853 9
|
测试技术 开发者
基础测试用例
顾翔 作者相关精选 基础测试用例 关注作者 腾讯云 开发者社区 免费试用云直播,了解直播推流的操作方式 文档 建议反馈 控制台 登录/注册 首页 学习 活动 专区 圈层 工具 MCP广场 文章/答案/技术大牛 搜索 发布 社区首页 > 专栏 > 基础测试用例 基础测试用例
507 40
|
12月前
|
存储 Java Maven
服务端(DevBox)-项目创建
使用Sealos创建SpringBoot工程zxyf-management,配置Java语言、3.3.2版本,2核CPU、4G内存,通过Devbox在云端搭建开发环境。利用Cursor智能工具打开项目,自动识别Maven结构,一键启动运行,实现高效云端开发。
|
存储 监控 安全
RFID小区电动车实施智能化监管模式
RFID技术助力小区电动车智能管理,通过电子标签实现车辆进出、停放、充电全流程监管,杜绝入户充电、乱停乱放、盗窃等隐患,提升安全与管理效率,推动智慧社区建设。(238字)
|
JavaScript API 微服务
探索现代后端开发:关键技术和最佳实践
【10月更文挑战第6天】探索现代后端开发:关键技术和最佳实践
|
安全 算法 网络安全
干货!ER系列路由器 IPSEC VPN配置方法!
干货!ER系列路由器 IPSEC VPN配置方法!
1433 7
|
前端开发 数据管理 数据处理
Django的MTV
【8月更文挑战第13天】
633 4
|
NoSQL Ubuntu Linux
基于ARM64的Qemu/KVM学习环境搭建2
基于ARM64的Qemu/KVM学习环境搭建2
给input框设置成选择日期,并且精确到时分秒
给input框设置成选择日期,并且精确到时分秒
1319 1