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 
 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 } 

 

转载于:https://www.cnblogs.com/wenzhixin/p/8543776.html

你可能感兴趣的:(zoj Beautiful Number(打表))