Description
Mike is very lucky, as he has both beautiful numbers, 3 and 5. But he's so greedy, that he wants infinite beautiful numbers. So he declares this any positive number which be dividable by 3 or 5 is beautiful number. Given you an integer n (1 <= n <= 100000), could do you have to tell Mike the Nth beautiful number?
Input
The input consists of one or more test cases. For each test case, the there is a single line containing an integer N.
Output
The For each test is in the input, and the result on a line by itself is output.
Sample Input
1
2
3
4
Sample Output
3
5
6
9
The number that can be divisible by 3 or 5 is a beautiful number, the value of the nth beautiful number.
My train of thought was simple, and began to fear timeouts, but did not.
Figure out all the beautiful numbers. There is an array in which the direct subscript minus one is the end of the output.
The code is as follows:
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n=0,i=3,num;
Vector<int> v;
while (true)
{
if (n>100000) break
;
if (i%3==0| | i%5==0)
{
v.push_back (i);
n++;
}
i++;
}
while (cin>>num)
cout<<v[num-1]<<endl;
}