码迷,mamicode.com
首页 > 其他好文 > 详细

zoj Beautiful Number(打表)

时间:2018-03-11 14:42:26      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:漂亮   acm   lin   tar   targe   single   cas   input   return   

题目链接:

  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829

题目描述:

  Mike is very lucky, as he has two beautiful numbers, 3 and 5. But he is so greedy that he wants infinite beautiful numbers. So he declares that any positive number which is dividable by 3 or 5 is beautiful number. Given you an integer N (1 <= N <= 100000), could you please tell mike the Nth beautiful number?

Input

The input consists of one or more test cases. For each test case, there is a single line containing an integer N.

Output

For each test case in the input, output the result on a line by itself.

Sample Input

1
2
3
4

Sample Output

3
5
6
9

 1 /*问题 查询第几个漂亮数字是多少
 2 解题思路 一般来讲,最直观的做法是将创建一个10 0000的数组,将每个漂亮数存进数组,最后查询即可*/
 3 #include <cstdio>
 4 int bn[100010];
 5 int main()
 6 {
 7     int count=1,i=3;
 8     while(1)
 9     {
10         if(i % 3 == 0 || i % 5 == 0){
11             bn[count++]=i;
12             if(count > 100000)
13                 break;
14         }
15         i++;
16     }
17     int n;
18     while(scanf("%d",&n) != EOF)
19     {
20         printf("%d\n",bn[n]);
21     }
22     return 0;    
23 } 

 

zoj Beautiful Number(打表)

标签:漂亮   acm   lin   tar   targe   single   cas   input   return   

原文地址:https://www.cnblogs.com/wenzhixin/p/8543776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!