Fill This Form To Receive Instant Help
Homework answers / question archive / Andrew loves numbers whose prime factor includes 2,3 or 5
Andrew loves numbers whose prime factor includes 2,3 or 5. He wants to know the Nth such number. Help Andrew find that.
Input:- N - nth number
Output:- Nth number matching Andrew’s specification.
note
Constraints
1<=N<=1650
view_list
Examples
Input:
10
Output:
12
Explanation:
1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 numbers matching Andrew’s specification.
label_important
Important Notes
1 is a part of the series
class solution
{
public:
int andrew_numbers(int n)
{
priority_queue,greater> pq;
pq.push(1);
int p,a;
p=-1;
for(int i=1;i<=s;i++)
{
while(pq.top()==p)
{
pq.pop();
}
a=pq.top();
pq.push(a*2);
pq.push(a*3);
pq.push(a*5);
p=a;
}
return a;
}
};