zoj Beautiful Number(打表)

Posted Reqaw’s Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zoj Beautiful Number(打表)相关的知识,希望对你有一定的参考价值。

题目链接:

  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(打表)的主要内容,如果未能解决你的问题,请参考以下文章

5179 beautiful number(数位dp)

ZOJ 2850: Beautiful Meadow

codeforces 893B Beautiful Divisors 打表

ZOJ How Many Nines 模拟 | 打表

G - G ZOJ - 2723 (素数打表+set)

zoj 2723 Semi-Prime(素筛打表+搜索优化)