"ACM Program Design" in the book title U

Source: Internet
Author: User

Topic Brief:

Describe
Mike was very lucky because he had two beautiful numbers, 3 and 5. But he was so greedy that he wanted the numbers to be infinitely beautiful. So he declares that any positive number that can be divided by 3 or 5 is beautiful. Given an integer n (1 <= n <= 100000), can you tell Mike the nth beautiful number?

The input consists of one or more test cases. For each test case, there is a row that contains an integer n.

For each test case in the input, output the results yourself.

For example:

Sample Input

1
2
3
4

Sample Output

3
5
6
9 Problem-Solving ideas:
The basic idea of this problem is simply to require a multiple of 3 or 5 to put it in an array in order.   When you enter N, you can find the corresponding number and then output it. In the actual operation, the first two times commit, ignoring the assignment of the last set of arrays, resulting in input 100000, the output is also 100000. There was also a problem with formatting control after the change, with a line break missing.
Attached code:
#include <bits/stdc++.h>
using namespace Std;
int main ()
{
int I, n, j = 0, S;
int a [100001];
for (i = 1, s = 1; s <= 100000; i + +)
{
if (i% 3 = = 0 | | I% 5 = = 0)
{
a [s]=i;
s + +;
}
}
while (CIN >>n)
{
cout <<a [n]<<endl;
}
return 0;
}
Problem-solving Experience:
This problem is really simple, to say what harvest, is to pay attention to the details of the problem, especially in the array assignment, pay attention to the first and last assignment problem. This is the first question of the night of March 9, it is easy to go through, happy ~ ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.